﻿var _transition = "none"; //flip

/// Account검색기능
var g_ContactView_q1;
var g_ContactView_q2;

var g_AccountView_q1;
var g_AccountView_q2;

var g_OpportunityView_q1;
var g_OpportunityView_q2;

var g_ActivateView_q1;
var g_ActivateView_q2;

var g_BillView_q1;
var g_BillView_q2;

var g_OrderView_q1;
var g_OrderView_q2;

var g_GroupView_q1;
var g_GroupView_q2;

var g_cursPage;
var g_cursUrl;
// -------------------------------------------------------------------------------------------
// Contact
// -------------------------------------------------------------------------------------------
// 목록검색동작
$('#page-ContactList').find('.btnsearch').live("vclick", function (evt) {

    SelectSvcMenu = $('#page-ContactList').find('.SelectAll .ui-btn-active').attr("SvcId");
    g_ContactView_q2 = $('#page-ContactList').find(".txtsearch").val();
    SetListview($('#page-ContactList').find('.ulMainList'), SelectSvcMenu, g_ContactView_q2);

});
// 목록 클릭시 이동
$('#page-ContactList').find('.liContactList').live("vclick", function (evt) {
    $.mobile.pageLoading();
    g_ContactView_q1 = $(this).attr('q1');
    $.mobile.changePage("/Account/ContactView.html", { transition: _transition });
    $.mobile.pageLoading(true);
});


$('#page-ContactGuideList').live("pageshow", function () {
    var v_width = $('#divGuide').width();

    $("#ifrGuide").width(v_width);
});

$('#page-ContactGuideList').find('.btnsearch').live("vclick", function (evt) {

    var SelectSvcMenu = $('#page-ContactGuideList').find('.SelectAll .ui-btn-active').attr("SvcId");

    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined) q1 = "0";
    if (q2 == undefined) q2 = "";

    g_ContactView_q2 = $('#page-ContactGuideList').find(".txtsearch").val();


    var pl = new JSONClientParameters();
    pl.add("SvcID", SelectSvcMenu);
    var pstr = "<DataTable><Record>";
    pstr += "<p1>" + g_ContactView_q2 + "</p1>";
    pstr += "<us>" + sm28 + "</us>";
    pstr += "</Record></DataTable>";
    pl.add("XmlParms", pstr);

    var _data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);

    frames["ifrGuide"].MapInit();

    if (_data == undefined) return false;
    var Rows = _data.Records.length;
    var i = 0;
    for (i; i < Rows; i++) {
        var _ADDRESS = _data.Records[i].ADDRESS;
        var _CSTNAME = _data.Records[i].CSTNAME;
        var _COMPANY = _data.Records[i].COMPANY;
        var _TITLE = _COMPANY + " " + _CSTNAME;
        var _TEL = _data.Records[i].WRKTELref;
        if (_TEL == undefined) { _TEL = ""; }
        _TITLE = _TITLE + "<p>" + _TEL + "</p>";

        frames["ifrGuide"].showAddress(_ADDRESS, _TITLE);


    }

});
//결재
$('#page-ApprovalList').live("pageshow", function () {

    var SelectSvcMenu = $('#page-ApprovalList').find('.SelectAll .ui-btn-active').attr("SvcId");
    SetListview($('#page-ApprovalList').find('.ulMainList'), SelectSvcMenu, "");

});
$('#page-ApprovalList').find('.btnsearch').live("vclick", function (evt) {

    var SelectSvcMenu = $('#page-ApprovalList').find('.SelectAll .ui-btn-active').attr("SvcId");
    g_ContactView_q2 = $('#page-ApprovalList').find(".txtsearch").val();
    SetListview($('#page-ApprovalList').find('.ulMainList'), SelectSvcMenu, g_ContactView_q2);
});
// 목록 클릭시 이동
$('#page-ApprovalList').find('.liActivateList').live("vclick", function (evt) {
    $.mobile.pageLoading();
    g_ContactView_q1 = $(this).attr('q1');
    $.mobile.changePage("/Approval/ApprovalView.html", { transition: _transition });
    $.mobile.pageLoading(true);
});
$('#page-ApprovalView').live("pagecreate", function () {

    $(this).find('.btnsearch').live("vclick", function (evt) {
        var SelectSvcMenu = $('#page-ApprovalView').find('.SelectAll .ui-btn-active').attr("SvcId");

        SetListview($('#page-ApprovalView').find('.ulMainList'), SelectSvcMenu, $('#page-ApprovalView').find(".txtsearch").val());
    });

    //우측목록 검색클릭동작시 
    $(this).find('.liActivateList').live("vclick", function (evt) {
        g_ContactView_q1 = $(this).attr('q1');

        SetValue($('#page-ApprovalView').find('.DataUl'), "ApprovalView", g_ContactView_q1);

        //결재자 라인정보 가져오기
        SetListview($('#page-ApprovalView .ulAPPList'), 'ApprovalFlow', g_ContactView_q1);

        window.scrollTo(0, 0);
    });

});
$('#page-ApprovalView').live("pageshow", function () {

    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined) q1 = "0";
    if (q2 == undefined) q2 = "";

    //$(this).find(".txtsearch").val(q2);
    $(this).data("q1", q1);

    // 고객상세
    SetValue($('#page-ApprovalView').find('.DataUl'), 'ApprovalView', q1);

    //결재자 라인정보 가져오기
    SetListview($('#page-ApprovalView .ulAPPList'), 'ApprovalFlow', q1);

    //결재양식본문
    /*var pl = new JSONClientParameters();
    pl.add("SvcID", "ApprovalContents");
    var pstr = "<DataTable><Record>";
    pstr += "<p1>" + q1 + "</p1>";
    pstr += "<us>" + sm28 + "</us>";
    pstr += "</Record></DataTable>";
    pl.add("XmlParms", pstr);

    var _data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);
    var _CONTENTS = _data.Records[0].CONTENTS;

    $("div [field='CONTENTS']", "#page-ApprovalView").html(_CONTENTS);
    */

});

//서비스
$('#page-ServiceList').live("pageshow", function () {

    var SelectSvcMenu = $('#page-ServiceList').find('.SelectAll .ui-btn-active').attr("SvcId");
    SetListview($('#page-ServiceList').find('.ulMainList'), SelectSvcMenu, "");

});
$('#page-ServiceList').find('.btnsearch').live("vclick", function (evt) {

    var SelectSvcMenu = $('#page-ServiceList').find('.SelectAll .ui-btn-active').attr("SvcId");
    g_ContactView_q2 = $('#page-ServiceList').find(".txtsearch").val();

     SetListview($('#page-ServiceList').find('.ulMainList'), SelectSvcMenu, g_ContactView_q2);
 });
 $('#page-ServiceList').find('.liContactList').live("vclick", function (evt) {
     $.mobile.pageLoading();
     g_ContactView_q1 = $(this).attr('q1');
     $.mobile.changePage("/Service/ServiceView.html", { transition: _transition });
     $.mobile.pageLoading(true);
 });
 
 
 $('#page-ServiceCreate').live("pageshow", function () {



     var q1 = getUrlVars()["q1"];
     var q2 = getUrlVars()["q2"];
     if (q1 == undefined) q1 = g_ContactView_q1;
     if (q2 == undefined) q2 = g_ContactView_q2;
     if (q1 == undefined) q1 = $('#page-ServiceView').data("q1");
     if (q1 == undefined || q1 == "") q1 = "0";
     if (q2 == undefined || q2 == "") q2 = "";



     var pl = new JSONClientParameters();
     pl.add("SvcID", "ServiceView");
     var pstr = "<DataTable><Record>";
     pstr += "<p1>" + q1 + "</p1>";
     pstr += "<us>" + sm28 + "</us>";
     pstr += "</Record></DataTable>";
     pl.add("XmlParms", pstr);

     var _data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);

     if (_data == undefined) return false;
     var Rows = _data.Records.length;

     if (Rows > 0) {
         var _CSTIDNM = _data.Records[0].CSTID_;
         var _CASEID = _data.Records[0].CASEID;
         var _RCVDESC1 = _data.Records[0].RCVDESC1;
         var _CASENAME = _data.Records[0].CASENAME;
         var _CASECODEID_ = _data.Records[0].CASECODEID_;
         var _RCVDESC2 = _data.Records[0].RCVDESC2;
         var _CASEDESC = _data.Records[0].CASEDESC;
         var _RACTDATE = _data.Records[0].RACTDATE;
         var _DEPTHCODE = _data.Records[0].DEPTHCODE;
         var _ACTDESC = _data.Records[0].ACTDESC;
         var _RACTLOGINID_ = _data.Records[0].RACTLOGINID_;
         var _TIME3 = _data.Records[0].TIME3;
         var _MIN3 = _data.Records[0].MIN3;
         var _ACTDURATION = _data.Records[0].ACTDURATION;

         //CASEID
         $("#page-ServiceCreate p[FIELD='CSTID_']").html(_CSTIDNM);
         $("#page-ServiceCreate p[FIELD='CASEID']").html(_CASEID);
         $("#page-ServiceCreate p[FIELD='RCVDESC1']").html(_RCVDESC1);
         $("#page-ServiceCreate p[FIELD='CASENAME']").html(_CASENAME);
         $("#page-ServiceCreate p[FIELD='CASECODEID_']").html(_CASECODEID_);
         $("#page-ServiceCreate p[FIELD='RCVDESC2']").html(_RCVDESC2);
         $("#page-ServiceCreate [FIELD='CASEDESC']").html(_CASEDESC);

         $("#page-ServiceCreate").find("#dtRACTDATE").val(_RACTDATE);
         $("#page-ServiceCreate").find("#txtACTDESC").val(_ACTDESC);

         $("#page-ServiceCreate #selDEPTHCODE option").removeAttr("selected");
         $("#page-ServiceCreate #selDEPTHCODE option[value='" + _DEPTHCODE + "']").attr("selected", true);
         $("#page-ServiceCreate #selDEPTHCODE").parent().find(".ui-btn-text").html($("#page-ServiceCreate #selDEPTHCODE option:selected").text());


         $("#page-ServiceCreate [FIELD='ACTDURATION']").val(_ACTDURATION);
         $("#page-ServiceCreate [FIELD='RACTLOGINID_']").html(_RACTLOGINID_);
     }



     //수정
     $('#page-ServiceCreate').find('.btnModify').live("vclick", function (evt) {
         var q1 = getUrlVars()["q1"];
         var q2 = getUrlVars()["q2"];
         if (q1 == undefined) q1 = g_ContactView_q1;
         if (q2 == undefined) q2 = g_ContactView_q2;
         if (q1 == undefined) q1 = $('#page-ServiceView').data("q1");
         if (q1 == undefined || q1 == "") q1 = "0";
         if (q2 == undefined || q2 == "") q2 = "";

         try {

             var _CASEID;
             var _CSTID;
             var _CLIID;
             var _CASENAME;
             var _RCVDATE;
             var _RCVTIME;
             var _RCVTYPE;
             var _RCVCHANNEL;
             var _RCVLOGINID;
             var _CASECODEID;

             var _PRDID;
             var _PRIORITY;
             var _CASEDESC;
             var _ACTIONTYPE;
             var _COSTTYPE;
             var _DACTDATE;
             var _DACTTIME;
             var _FACTDATE;
             var _ACTOPINION;
             var _ASSIGNDATE;

             var _ASGNNOTICEDATE;
             var _ACTCODE;
             var _ACTDESC;
             var _RACTLOGINID;
             var _RACTDATE;
             var _RACTTIME;
             var _ACTDURATION;
             var _NOTICECHANNEL;
             var _CSTNAME;
             var _MAILTO;

             var _ZIPID;
             var _UPRADDRESS;
             var _LWRADDRESS;
             var _TELNO1;
             var _TELNO2;
             var _TELNO3;
             var _FAXTEL1;
             var _FAXTEL2;
             var _FAXTEL3;
             var _MOBILE1;

             var _MOBILE2;
             var _MOBILE3;
             var _EMAIL;
             var _POUSER;
             var _PRCSTATE;
             var _DEPTHCODE;
             var _MODELCODE;
             var _SERIAL;
             var _SHIPPERDATE;
             var _BUYDATE;

             var _CNFID;
             var _QUERYUSER;
             var _PRDSN;
             var _SVCNOTIFY;
             var _RECFILENAME;
             var _RECFILEDATE;
             var _CALLBACKID;

             var pl = new JSONClientParameters();
             pl.add("SvcID", "ServiceView");
             var pstr = "<DataTable><Record>";
             pstr += "<p1>" + q1 + "</p1>";
             pstr += "<us>" + sm28 + "</us>";
             pstr += "</Record></DataTable>";
             pl.add("XmlParms", pstr);

             var _data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);

             if (_data == undefined) return false;
             var Rows = _data.Records.length;

             if (Rows > 0) {

                 var _CASEID = _data.Records[0].CASEID;
                 var _CSTID = (_data.Records[0].CSTID == undefined) ? "0" : _data.Records[0].CSTID;
                 var _CLIID = (_data.Records[0].CLIID == undefined) ? "0" : _data.Records[0].CLIID;
                 var _CASENAME = (_data.Records[0].CASENAME == undefined) ? "" : _data.Records[0].CASENAME;
                 var _RCVDATE = (_data.Records[0].RCVDATE == undefined) ? "" : _data.Records[0].RCVDATE;
                 var _RCVTIME = (_data.Records[0].RCVTIME == undefined) ? "" : _data.Records[0].RCVTIME;
                 var _RCVTYPE = (_data.Records[0].RCVTYPE == undefined) ? "0" : _data.Records[0].RCVTYPE;
                 var _RCVCHANNEL = (_data.Records[0].RCVCHANNEL == undefined) ? "0" : _data.Records[0].RCVCHANNEL;
                 var _RCVLOGINID = (_data.Records[0].RCVLOGINID == undefined) ? "0" : _data.Records[0].RCVLOGINID;
                 var _CASECODEID = (_data.Records[0].CASECODEID == undefined) ? "0" : _data.Records[0].CASECODEID;

                 var _PRDID = (_data.Records[0].PRDID == undefined) ? "0" : _data.Records[0].PRDID;
                 var _PRIORITY = (_data.Records[0].PRIORITY == undefined) ? "0" : _data.Records[0].PRIORITY;
                 var _CASEDESC = (_data.Records[0].CASEDESC == undefined) ? "" : _data.Records[0].CASEDESC;
                 var _ACTIONTYPE = (_data.Records[0].ACTIONTYPE == undefined) ? "0" : _data.Records[0].ACTIONTYPE;
                 var _COSTTYPE = (_data.Records[0].COSTTYPE == undefined) ? "0" : _data.Records[0].COSTTYPE;
                 var _DACTDATE = (_data.Records[0].DACTDATE == undefined) ? "" : _data.Records[0].DACTDATE;
                 var _DACTTIME = (_data.Records[0].DACTTIME == undefined) ? "" : _data.Records[0].DACTTIME;
                 var _FACTDATE = (_data.Records[0].FACTDATE == undefined) ? "" : _data.Records[0].FACTDATE;
                 var _ACTOPINION = (_data.Records[0].ACTOPINION == undefined) ? "" : _data.Records[0].ACTOPINION;
                 var _ASSIGNDATE = (_data.Records[0].ASSIGNDATE == undefined) ? "" : _data.Records[0].ASSIGNDATE;

                 var _ASGNNOTICEDATE = (_data.Records[0].ASGNNOTICEDATE == undefined) ? "" : _data.Records[0].ASGNNOTICEDATE;
                 var _ACTCODE = (_data.Records[0].ACTCODE == undefined) ? "0" : _data.Records[0].ACTCODE;
                 var _ACTDESC = $("#txtACTDESC").val(); //_data.Records[0].ACTDESC;
                 var _RACTLOGINID = (_data.Records[0].RACTLOGINID == undefined) ? "0" : _data.Records[0].RACTLOGINID;
                 var _RACTDATE = $("#dtRACTDATE")[0].value; //_data.Records[0].RACTDATE;
                 var _RACTTIME = _data.Records[0].RACTTIME;
                 var _ACTDURATION = ($("#txtACTDURATION").val() == undefined) ? "0" : $("#txtACTDURATION").val();  //(_data.Records[0].ACTDURATION == undefined) ? "0" : _data.Records[0].ACTDURATION;
                 var _NOTICECHANNEL = (_data.Records[0].NOTICECHANNEL == undefined) ? "0" : _data.Records[0].NOTICECHANNEL;
                 var _CSTNAME = (_data.Records[0].CSTNAME == undefined) ? "" : _data.Records[0].CSTNAME;
                 var _MAILTO = (_data.Records[0].MAILTO == undefined) ? "" : _data.Records[0].MAILTO;

                 var _ZIPID = (_data.Records[0].ZIPID == undefined) ? "" : _data.Records[0].ZIPID;
                 var _UPRADDRESS = (_data.Records[0].UPRADDRESS == undefined) ? "" : _data.Records[0].UPRADDRESS;
                 var _LWRADDRESS = (_data.Records[0].LWRADDRESS == undefined) ? "" : _data.Records[0].LWRADDRESS;
                 var _TELNO1 = (_data.Records[0].TELNO1 == undefined) ? "" : _data.Records[0].TELNO1;
                 var _TELNO2 = (_data.Records[0].TELNO2 == undefined) ? "" : _data.Records[0].TELNO2;
                 var _TELNO3 = (_data.Records[0].TELNO3 == undefined) ? "" : _data.Records[0].TELNO3;
                 var _FAXTEL1 = (_data.Records[0].FAXTEL1 == undefined) ? "" : _data.Records[0].FAXTEL1;
                 var _FAXTEL2 = (_data.Records[0].FAXTEL2 == undefined) ? "" : _data.Records[0].FAXTEL2;
                 var _FAXTEL3 = (_data.Records[0].FAXTEL3 == undefined) ? "" : _data.Records[0].FAXTEL3;
                 var _MOBILE1 = (_data.Records[0].MOBILE1 == undefined) ? "" : _data.Records[0].MOBILE1;

                 var _MOBILE2 = (_data.Records[0].MOBILE2 == undefined) ? "" : _data.Records[0].MOBILE2;
                 var _MOBILE3 = (_data.Records[0].MOBILE3 == undefined) ? "" : _data.Records[0].MOBILE3;
                 var _EMAIL = (_data.Records[0].EMAIL == undefined) ? "" : _data.Records[0].EMAIL;
                 var _POUSER = (_data.Records[0].POUSER == undefined) ? "" : _data.Records[0].POUSER;
                 var _PRCSTATE = (_data.Records[0].PRCSTATE == undefined) ? "0" : _data.Records[0].PRCSTATE;
                 var _DEPTHCODE = ($("#selDEPTHCODE option:selected").val() == "") ? "NULL" : $("#selDEPTHCODE option:selected").val(); //_data.Records[0].DEPTHCODE;
                 var _MODELCODE = (_data.Records[0].MODELCODE == undefined) ? "" : _data.Records[0].MODELCODE;
                 var _SERIAL = (_data.Records[0].SERIAL == undefined) ? "" : _data.Records[0].SERIAL;
                 var _SHIPPERDATE = (_data.Records[0].SHIPPERDATE == undefined) ? "" : _data.Records[0].SHIPPERDATE;
                 var _BUYDATE = (_data.Records[0].BUYDATE == undefined) ? "" : _data.Records[0].BUYDATE;

                 var _CNFID = (_data.Records[0].CNFID == undefined) ? "0" : _data.Records[0].CNFID;
                 var _QUERYUSER = (_data.Records[0].QUERYUSER == undefined) ? "0" : _data.Records[0].QUERYUSER;
                 var _PRDSN = (_data.Records[0].PRDSN == undefined) ? "" : _data.Records[0].PRDSN;
                 var _SVCNOTIFY = (_data.Records[0].SVCNOTIFY == undefined) ? "0" : _data.Records[0].SVCNOTIFY;
                 var _RECFILENAME = (_data.Records[0].RECFILENAME == undefined) ? "" : _data.Records[0].RECFILENAME;
                 var _RECFILEDATE = (_data.Records[0].RECFILEDATE == undefined) ? "" : _data.Records[0].RECFILEDATE;
                 var _CALLBACKID = (_data.Records[0].CALLBACKID == undefined) ? "0" : _data.Records[0].CALLBACKID;
             }



             //수정   
             var pl = new JSONClientParameters();
             pl.add("SvcID", "ServiceCreate");
             var pstr = "<DataTable><Record>";
             pstr += "<p1>" + _CASEID + "</p1>";
             pstr += "<p2>" + _CSTID + "</p2>";
             pstr += "<p3>" + _CLIID + "</p3>";
             pstr += "<p4>" + _CASENAME + "</p4>";
             pstr += "<p5>" + _RCVDATE + "</p5>";
             pstr += "<p6>" + _RCVTIME + "</p6>";
             pstr += "<p7>" + _RCVTYPE + "</p7>";
             pstr += "<p8>" + _RCVCHANNEL + "</p8>";
             pstr += "<p9>" + _RCVLOGINID + "</p9>";
             pstr += "<p10>" + _CASECODEID + "</p10>";

             pstr += "<p11>" + _PRDID + "</p11>";
             pstr += "<p12>" + _PRIORITY + "</p12>";
             pstr += "<p13>" + _CASEDESC + "</p13>";
             pstr += "<p14>" + _ACTIONTYPE + "</p14>";
             pstr += "<p15>" + _COSTTYPE + "</p15>";
             pstr += "<p16>" + _DACTDATE + "</p16>";
             pstr += "<p17>" + _DACTTIME + "</p17>";
             pstr += "<p18>" + _FACTDATE + "</p18>";
             pstr += "<p19>" + _ACTOPINION + "</p19>";
             pstr += "<p20>" + _ASSIGNDATE + "</p20>";

             pstr += "<p21>" + _ASGNNOTICEDATE + "</p21>";
             pstr += "<p22>" + _ACTCODE + "</p22>";
             pstr += "<p23>" + _ACTDESC + "</p23>";
             pstr += "<p24>" + _RACTLOGINID + "</p24>";
             pstr += "<p25>" + _RACTDATE + "</p25>";
             pstr += "<p26>" + _RACTTIME + "</p26>";
             pstr += "<p27>" + _ACTDURATION + "</p27>";
             pstr += "<p28>" + _NOTICECHANNEL + "</p28>";
             pstr += "<p29>" + _CSTNAME + "</p29>";
             pstr += "<p30>" + _MAILTO + "</p30>";

             pstr += "<p31>" + _ZIPID + "</p31>";
             pstr += "<p32>" + _UPRADDRESS + "</p32>";
             pstr += "<p33>" + _LWRADDRESS + "</p33>";
             pstr += "<p34>" + _TELNO1 + "</p34>";
             pstr += "<p35>" + _TELNO2 + "</p35>";
             pstr += "<p36>" + _TELNO3 + "</p36>";
             pstr += "<p37>" + _FAXTEL1 + "</p37>";
             pstr += "<p38>" + _FAXTEL2 + "</p38>";
             pstr += "<p39>" + _FAXTEL3 + "</p39>";
             pstr += "<p40>" + _MOBILE1 + "</p40>";

             pstr += "<p41>" + _MOBILE2 + "</p41>";
             pstr += "<p42>" + _MOBILE3 + "</p42>";
             pstr += "<p43>" + _EMAIL + "</p43>";
             pstr += "<p44>" + _POUSER + "</p44>";
             pstr += "<p45>" + _PRCSTATE + "</p45>";
             pstr += "<p46>" + _DEPTHCODE + "</p46>";
             pstr += "<p47>" + _MODELCODE + "</p47>";
             pstr += "<p48>" + _SERIAL + "</p48>";
             pstr += "<p49>" + _SHIPPERDATE + "</p49>";
             pstr += "<p50>" + _BUYDATE + "</p50>";

             pstr += "<p51>" + _CNFID + "</p51>";
             pstr += "<p52>" + _QUERYUSER + "</p52>";
             pstr += "<p53>" + _PRDSN + "</p53>";
             pstr += "<p54>" + _SVCNOTIFY + "</p54>";
             pstr += "<p55>" + _RECFILENAME + "</p55>";
             pstr += "<p56>" + _RECFILEDATE + "</p56>";
             pstr += "<p57>" + _CALLBACKID + "</p57>";

             pstr += "<us>" + sm28.replace('T', '') + "</us>";
             pstr += "</Record></DataTable>";

             //alert("pstr:" + pstr);
             pl.add("XmlParms", pstr);
             PostStrSync("/bzService/DBProxy.asmx/execRun", pl);



         }
         catch (e) {
             alert(e.toString());
         }
     });



 });

 $('#page-ServiceView').live("pagecreate", function (evt) {
     var q1 = getUrlVars()["q1"];
     var q2 = getUrlVars()["q2"];
     if (q1 == undefined) q1 = g_ContactView_q1;
     if (q2 == undefined) q2 = g_ContactView_q2;
     if (q1 == undefined) q1 = $('#page-ServiceView').data("q1");
     if (q1 == undefined) q1 = "0";
     if (q2 == undefined) q2 = "";

     $(this).find('.btnsearch').live("vclick", function (evt) {

         var SelectSvcMenu = $('#page-ServiceView').find('.SelectAll .ui-btn-active').attr("SvcId");
         g_ContactView_q2 = $('#page-ServiceView').find(".txtsearch").val();
         SetListview($('#page-ServiceView').find('.ulContactList'), SelectSvcMenu, g_ContactView_q2);
     });
     $(this).find('.liContactList').live("vclick", function (evt) {

         g_ContactView_q1 = $(this).attr('q1');

         $("#page-ServiceView #txtACTDESC").html("");
         $("#page-ServiceView [field='ACTDURATION']").html("");
         $("#page-ServiceView [field='DEPTHCODE_']").html("");
         $("#page-ServiceView [field='RACTLOGINID_']").html("");

         SetValue($('#page-ServiceView').find('.DataUl'), 'ServiceView', g_ContactView_q1);


     });

     $(this).find('.btnModify').live("vclick", function (evt) {

         $.mobile.changePage("/Service/ServiceCreate.html", { transition: _transition });

         $('#page-ServiceCreate').data("mode", "edit");

     });

 });

 $('#page-ServiceView').live("pageshow", function () {

     var q1 = getUrlVars()["q1"];
     var q2 = getUrlVars()["q2"];
     if (q1 == undefined) q1 = g_ContactView_q1;
     if (q2 == undefined) q2 = g_ContactView_q2;
     if (q1 == undefined) q1 = "0";
     if (q2 == undefined) q2 = "";

     //$('#page-ServiceView').find(".txtsearch").val(q2);
     $('#page-ServiceView').data("q1", q1);

     $("#page-ServiceView #txtACTDESC").html("");
     $("#page-ServiceView [field='ACTDURATION']").html("");
     $("#page-ServiceView [field='DEPTHCODE_']").html("");
     $("#page-ServiceView [field='RACTLOGINID_']").html("");
     
     SetValue($('#page-ServiceView').find('.DataUl'), 'ServiceView', q1);



 });

//고객
 $('#page-ContactList').live("pageshow", function () {

     var SelectSvcMenu = $('#page-ContactList').find('.SelectAll .ui-btn-active').attr("SvcId");
     if (SelectSvcMenu == undefined) SelectSvcMenu = "ContactListMy";
     SetListview($('#page-ContactList').find('.ulMainList'), SelectSvcMenu, "");

 });
 $('#page-ContactList').find('#aNew').live("vclick", function (evt) {

     var $page = $('#page-ContactCreateCus');


     $page.find('#txtCSTNAME').val("");
     $page.find('#txtCOMPANY').val("");
     $page.find('#txtWRKTEL1').val("");
     $page.find('#txtWRKTEL2').val("");
     $page.find('#txtWRKTEL3').val("");
     $page.find('#txtMOBILE1').val("");
     $page.find('#txtMOBILE2').val("");
     $page.find('#txtMOBILE3').val("");
     $page.find('#txtWRKFAXTEL1').val("");
     $page.find('#txtWRKFAXTEL2').val("");
     $page.find('#txtWRKFAXTEL3').val("");
     $page.find('#txtEMAIL').val("");
     $page.find('#txtWRKUPRADDRESS').val("");
     $page.find('#txtWRKLWRADDRESS').val("");
     $page.find('#selCLIENTTYPE').val(0);

     g_ContactView_q1 = "";

     $.mobile.changePage("/Account/ContactCreateCus.html", { transition: _transition });
     $.mobile.pageLoading(true);

     $page.data("mode", "new");
 });


$('#page-ContactView').live("pageshow", function () {

    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined) q1 = "0";
    if (q2 == undefined) q2 = "";

    //$(this).find(".txtsearch").val(q2);
    $(this).data("q1", q1);

    // 고객상세
    SetValue($('#page-ContactView').find('.DataUl'), 'ContactView', q1);
    // 접촉이력탭
    SelectSvcMenu = $('#page-ContactView').find('.SelectTab .ui-btn-active').attr("SvcId");
    if (SelectSvcMenu == undefined || SelectSvcMenu == "") {
        SelectSvcMenu = "ContactMeetList";
    }
    SetListview($('#page-ContactView').find('.ulContactMeetList'), SelectSvcMenu, q1);


    var pl = new JSONClientParameters();
    pl.add("SvcID", "ContactView");
    var pstr = "<DataTable><Record>";
    pstr += "<p1>" + q1 + "</p1>";
    pstr += "<us>" + sm28 + "</us>";
    pstr += "</Record></DataTable>";
    pl.add("XmlParms", pstr);

    var _data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);
    var _OWNER = _data.Records[0].OWNER;

    if (_OWNER == sm28.replace("T", "")) {
        $(this).find('.btnModify').toggle(true);
        $(this).find('.btnDelete').toggle(true);
    } else {
        $(this).find('.btnModify').toggle(false);
        $(this).find('.btnDelete').toggle(false);
    }

});

$('#page-ContactView').live("pagecreate", function () {
    // 우측목록보이기
    //    SetListview($('#page-ContactView').find('.ulContactList'), 'ContactList', $('#page-ContactView').find(".txtsearch").val());
    //우축목록 검색클릭동작
    $(this).find('.btnsearch').live("vclick", function (evt) {
        SetListview($('#page-ContactView').find('.ulContactList'), 'ContactList', $('#page-ContactView').find(".txtsearch").val());
    });
    //우측목록 검색클릭동작시 
    $(this).find('.liContactList').live("vclick", function (evt) {
        g_ContactView_q1 = $(this).attr('q1');
        //alert(g_ContactView_q1 + ' / ' + sm28);
        SetValue($('#page-ContactView').find('.DataUl'), 'ContactView', g_ContactView_q1);
        SetListview($('#page-ContactView').find('.ulContactMeetList'), 'ContactMeetList', g_ContactView_q1);
        window.scrollTo(0, 0);
    });

    //접촉이력,영업,서비스 항목 가져오기 2012.02.15 khpark
    $(this).find('.SelectTab').live("vclick", function (evt) {
        var q1 = getUrlVars()["q1"];
        var q2 = getUrlVars()["q2"];
        if (q1 == undefined) q1 = g_ContactView_q1;
        if (q2 == undefined) q2 = g_ContactView_q2;
        if (q1 == undefined) q1 = "0";
        if (q2 == undefined) q2 = "";

        SelectSvcMenu = $('#page-ContactView').find('.SelectTab .ui-btn-active').attr("SvcId");
        $('#page-ContactView').find('.ulContactMeetList').html('');

        SetListview($('#page-ContactView').find('.ulContactMeetList'), SelectSvcMenu, q1);

    });

    $('#page-ContactView').find('.btnDelete').live("vclick", function (evt) {
        var q1 = getUrlVars()["q1"];
        var q2 = getUrlVars()["q2"];
        if (q1 == undefined) q1 = g_ContactView_q1;
        if (q2 == undefined) q2 = g_ContactView_q2;
        if (q1 == undefined) q1 = $('#page-ContactView').data("q1");
        if (q1 == undefined || q1 == "") q1 = "0";
        if (q2 == undefined || q2 == "") q2 = "";

        var cfm = confirm("정말 삭제하시겠습니까?");

        if (cfm == true) {

            try {

                var pl = new JSONClientParameters();
                pl.add("SvcID", "ContactDelete");
                var pstr = "<DataTable><Record>";
                pstr += "<p1>" + q1 + "</p1>";
                pstr += "<p2></p2>";
                pstr += "<us>" + sm28.replace('T', '') + "</us>";
                pstr += "</Record></DataTable>";

                // alert("pstr:" + pstr);
                pl.add("XmlParms", pstr);
                PostStrSync("/bzService/DBProxy.asmx/execRun", pl);



            }
            catch (e) {
                alert(e.toString());
            }
        } else {
            return false;
        }

    });

});
//서비스 상세보기 링크 
$('#page-ContactView').find('.liServiceList').live("vclick", function (evt) {
    $.mobile.pageLoading();
    //g_ContactView_q1 = $(this).attr('q1');
    g_ContactView_q2 = $(this).attr('q2');
    $.mobile.changePage("/Account/ContactServiceView.htm", { transition: _transition });
    $.mobile.pageLoading(true);
});
//영업 상세보기 링크 2012.02.06 khpark
$('#page-ContactView').find('.liBusinessList').live("vclick", function (evt) {
    $.mobile.pageLoading();
    g_ContactView_q1 = $(this).attr('q1');
    //g_ContactView_q2 = $(this).attr('q2');
    $.mobile.changePage("/Opportunity/OpportunityLinkView.html", { transition: _transition });    
    $.mobile.pageLoading(true);
});
// 접촉이력 상세보기 링크 2012.02.14 khpark
$('#page-ContactView').find('.liContactMeetList').live("vclick", function (evt) {
    $.mobile.pageLoading();
    //g_ContactView_q1 = $(this).attr('q1');
    g_ContactView_q2 = $(this).attr('q2');
    $.mobile.changePage("/Account/ContactMeetView.htm", { transition: _transition });
    $.mobile.pageLoading(true);
});
$('#page-ContactView').find('.btnModify').live("vclick", function (evt) {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_AccountView_q1;
    if (q2 == undefined) q2 = g_AccountView_q2;
    if (q1 == undefined) q1 = $('#page-ContactView').data("q1");
    if (q1 == undefined) q1 = "0";
    if (q2 == undefined) q2 = "";

    $.mobile.changePage("/Account/ContactCreateCus.html", { transition: _transition });

    $('#page-ContactCreateCus').data("mode", "edit");
});


//서비스 정보 상세보기
$('#page-ContactServiceView').live("pagebeforeshow", function () {

    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined) q1 = "0";
    if (q2 == undefined) q2 = "";

    // 고객상세
    SetValue($('#page-ContactServiceView').find('.DataUl'), 'ContactServiceView', q2);

    // 접촉이력목록
    SetListview($('#page-ContactServiceView').find('.ulContactService'), 'ContactService', q1);

});
// 서비스 상세보기
$('#page-ContactServiceView').find('.liServiceList').live("vclick", function (evt) {
    $.mobile.pageLoading();
    //g_ContactView_q1 = $(this).attr('q1');
    g_ContactView_q2 = $(this).attr('q2');

    // 고객상세
    //$('#page-ContactServiceView').find('.DataUl').html('');
    SetValue($('#page-ContactServiceView').find('.DataUl'), 'ContactServiceView', g_ContactView_q2);

    $.mobile.pageLoading(true);
});
// 접촉이력 상세보기 2012.02.14 khpark
$('#page-ContactMeetDetail').live("pageshow", function () {

    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined) q1 = "0";
    if (q2 == undefined) q2 = "";

    // 고객상세
    SetValue($('#page-ContactMeetDetail').find('.DataUl'), 'ContactMeetDetail', q2); 

    // 접촉이력목록
    SetListview($('#page-ContactMeetDetail').find('.ulContactMeetList'), 'ContactMeetList', q1);


    // 목록검색동작
    $(this).find('.btnsearch').live("vclick", function (evt) {

        g_ContactView_q2 = $('#page-ContactMeetDetail').find(".txtsearch").val();
        SetListview($('#page-ContactMeetDetail').find('.ulContactList'), "ContactList", g_ContactView_q2);

    });
    // 목록 클릭시 이동
    $(this).find('.liContactList').live("vclick", function (evt) {
        $.mobile.pageLoading();
        g_ContactView_q1 = $(this).attr('q1');
        $.mobile.changePage("/Account/ContactView.html", { transition: _transition });
        $.mobile.pageLoading(true);
    });



});


// 접촉이력 상세보기 링크 2012.02.14 khpark
$('#page-ContactMeetDetail').find('.liContactMeetList').live("vclick", function (evt) {
    $.mobile.pageLoading();
    g_ContactView_q1 = $(this).attr('q1');
    g_ContactView_q2 = $(this).attr('q2');
        
    // 고객상세
    SetValue($('#page-ContactMeetDetail').find('.DataUl'), 'ContactMeetDetail', g_ContactView_q2);

    $.mobile.pageLoading(true);
});

$('#page-ContactCreate').live("pageshow", function () {
    $(this).find("#NewContacttextarea").val("");
    SetCodeList($("#ContactCreate_select_Sales"), "ActivateOpportunity", g_ContactView_q1);
});

$('#page-ContactCreate').live("pagecreate", function () {

    $(this).find('.btnNewContact').live("vclick", function (evt) {
        //   $.mobile.pageLoading();
        salesid = $("#ContactCreate_select_Sales").val();
        if (salesid == undefined) salesid = "0";

        var pl = new JSONClientParameters();
        pl.add("SvcID", "ActivateCreate");
        var pstr = "<DataTable><Record>";
        pstr += "<p1>" + g_ContactView_q1 + "</p1>";
        pstr += "<p2>" + $("#page-ContactCreate").find("#NewContacttextarea").val() + "</p2>";
        pstr += "<p3>" + salesid + "</p3>";
        pstr += "<p4>" + sm28.replace('T', '') + "</p4>";
        pstr += "</Record></DataTable>";
        pl.add("XmlParms", pstr);
        PostStrSync("/bzService/DBProxy.asmx/execRun", pl);

    });

});


// -------------------------------------------------------------------------------------------
// 거래처 검색 팝업
// -------------------------------------------------------------------------------------------
$('#page-PopupAccount').live("pageshow", function () {
    $("#page-PopupAccount [SvcId='AccountListMy']").removeClass("ui-btn-active").addClass("ui-btn-active");

    var SelectSvcMenu = $('#page-PopupAccount').find('.SelectAll .ui-btn-active').attr("SvcId");
    if (SelectSvcMenu == undefined) SelectSvcMenu = "AccountListMy";
    SetListview($('#page-PopupAccount').find('.ulMainList'), SelectSvcMenu, "");

    // 목록 클릭시 이동
    $('#page-PopupAccount').find('.liAccountList').live("vclick", function (evt) {
        g_AccountView_q1 = $(this).attr('q1');
        var v_title = $(this).attr('title');
        var v_callname = $(this).attr('callname');



        var v_page = g_cursPage;
        var v_url = g_cursUrl;

        $.mobile.changePage(v_url, { transition: _transition });

        v_page = "#page-" + v_page;
        $(v_page).find('#txtCLIID').val(g_AccountView_q1);
        $(v_page).find('#txtCOMPANY').val(v_title);

        if ($(v_page).find('#txtCALLNAME') != undefined && v_callname != undefined) {
            $(v_page).find('#txtCALLNAME').val(v_callname);
        }

    });


});

// 목록검색동작
$('#page-PopupAccount').find('.btnsearch').live("vclick", function (evt) {
    var $page = $('#page-PopupAccount');
    var SelectSvcMenu = $page.find('.SelectAll .ui-btn-active').attr("SvcId");
    if (SelectSvcMenu == undefined) SelectSvcMenu = "AccountListMy";
    SetListview($page.find('.ulMainList'), SelectSvcMenu, $page.find(".txtsearch").val());
});


// -------------------------------------------------------------------------------------------
// Account
// -------------------------------------------------------------------------------------------
// 목록 클릭시 이동
$('#page-AccountList').find('.liAccountList').live("vclick", function (evt) {
    g_AccountView_q1 = $(this).attr('q1');
    $.mobile.changePage("/Account/AccountView.html", { transition: _transition });
});
// 목록검색동작
$('#page-AccountList').find('.btnsearch').live("vclick", function (evt) {

    SelectSvcMenu = $('#page-AccountList').find('.SelectAll .ui-btn-active').attr("SvcId");
    SetListview($('#page-AccountList').find('.ulMainList'), SelectSvcMenu, $('#page-AccountList').find(".txtsearch").val());
});

$('#page-AccountList').live("pageshow", function () {
    // 검색초기값 자동동작
    SelectSvcMenu = $('#page-AccountList').find('.SelectAll .ui-btn-active').attr("SvcId");
    SetListview($(this).find('.ulMainList'), SelectSvcMenu, "");
    //SetListview($(this).find('.ulMainList'), "AccountList", "");


});
$('#page-AccountList').find('#aNew').live("vclick", function (evt) {
    g_AccountView_q1 = "";// $(this).attr('q1');


    $.mobile.changePage("/Account/AccountCreate.html", { transition: _transition });
    $.mobile.pageLoading(true);

    $('#page-AccountCreate').data("mode", "new");

});

$('#page-AccountView').live("pagecreate", function () {

    //삭제
    $('#page-AccountView').find('.btnDelete').live("vclick", function (evt) {

        var cfm = confirm("정말 삭제하시겠습니까?");

        if (cfm == true) {
            try {

                var pl = new JSONClientParameters();
                pl.add("SvcID", "AccountDelete");
                var pstr = "<DataTable><Record>";
                pstr += "<p1>" + g_AccountView_q1 + "</p1>";
                pstr += "<p2></p2>";
                pstr += "<us>" + sm28.replace('T', '') + "</us>";
                pstr += "</Record></DataTable>";

                //alert("pstr:" + pstr);
                pl.add("XmlParms", pstr);
                PostStrSync("/bzService/DBProxy.asmx/execRun", pl);



            }
            catch (e) {
                alert(e.toString());
            }
        } else {
            return false;
        }

    });
});

$('#page-AccountView').live("pageshow", function () {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_AccountView_q1;
    if (q2 == undefined) q2 = g_AccountView_q2;
    if (q1 == undefined) q1 = "0";
    if (q2 == undefined) q2 = "";

    $(this).find(".txtsearch").val(q2);

    $('#page-AccountView').data("q1", q1);

    // 상세
    SetValue($('#page-AccountView').find('.DataUl'), 'AccountView', q1);
    // 거래처관련자탭
    SetListview($('#page-AccountView').find('.ulAccountContactList'), 'AccountContactList', q1);
    SetListview($('#page-AccountView').find('.ulAccountOpportunityList'), 'AccountOpportunityList', q1);
    SetListview($('#page-AccountView').find('.ulAccountOrderList'), 'AccountOrderList', q1);



    var pl = new JSONClientParameters();
    pl.add("SvcID", "AccountView");
    var pstr = "<DataTable><Record>";
    pstr += "<p1>" + q1 + "</p1>";
    pstr += "<us>" + sm28 + "</us>";
    pstr += "</Record></DataTable>";
    pl.add("XmlParms", pstr);

    var _data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);
    var _OWNER = _data.Records[0].OWNER;

    if (_OWNER == sm28.replace("T", "")) {
        $(this).find('.btnModify').toggle(true);
        $(this).find('.btnDelete').toggle(true);
    } else {
        $(this).find('.btnModify').toggle(false);
        $(this).find('.btnDelete').toggle(false);
    }


    //우축목록 검색클릭동작
    $('#page-AccountView').find('.btnsearch').live("vclick", function (evt) {
        SetListview($('#page-AccountView').find('.ulAccountList'), 'AccountList', $('#page-AccountView').find(".txtsearch").val());
    });
    //우측목록 검색클릭동작시 
    $('#page-AccountView').find('.liAccountList').live("vclick", function (evt) {
        q1 = $(this).attr('q1');
        $('#page-AccountView').data("q1", q1);

        SetValue($('#page-AccountView').find('.DataUl'), 'AccountView', q1);
        SetListview($('#page-AccountView').find('.ulAccountContactList'), 'AccountContactList', q1);
        SetListview($('#page-AccountView').find('.ulAccountOpportunityList'), 'AccountOpportunityList', q1);
        SetListview($('#page-AccountView').find('.ulAccountOrderList'), 'AccountOrderList', q1);
        window.scrollTo(0, 0);
    });

    $('#page-AccountView').find('.liContactList').live("vclick", function (evt) {
        g_ContactView_q1 = $(this).attr('q1');

        $.mobile.changePage("/Account/ContactView.html", { transition: _transition });

    });

    $('#page-AccountView').find('.liOrderList').live("vclick", function (evt) {
        g_OrderView_q1 = $(this).attr('q1');

        $.mobile.changePage("/Opportunity/OrderView.html", { transition: _transition });

    });
    $('#page-AccountView').find('.liList').live("vclick", function (evt) {
        //g_OpportunityView_q1 = $(this).attr('q1');
        g_ContactView_q1 = $(this).attr('q1');

        $.mobile.changePage("/Opportunity/OpportunityView.html", { transition: _transition });

    });

    



});
$('#page-AccountView').find('.btnModify').live("vclick", function (evt) {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_AccountView_q1;
    if (q2 == undefined) q2 = g_AccountView_q2;
    if (q1 == undefined) q1 = $('#page-AccountView').data("q1");
    //if (q1 == undefined && $(this).data("mode") == "edit") q1 = $('#page-AccountView').data("q1");
    if (q1 == undefined) q1 = "0";
    if (q2 == undefined) q2 = "";

    g_AccountView_q1 = q1;

    $.mobile.changePage("/Account/AccountModify.html", { transition: _transition });

    $('#page-AccountModify').data("mode", "edit");
});

// -------------------------------------------------------------------------------------------
// Schedule
// -------------------------------------------------------------------------------------------
var ScheduleMonth;
var isOffSet;

$('#page-Schedule').live("pagecreate", function () {

    $('#schdate').bind('datebox', function (e, p) {
        if (p.method == "offset") {
            isOffSet = true;
        }
        SelectSvcMenu = $('#page-Schedule').find('.SelectAll .ui-btn-active').attr("SvcId");

        if (p.method == "refresh" && isOffSet == true) {
            GetScheduleMonthList($(this).data('datebox').theDate.getFullYear(), $(this).data('datebox').theDate.getMonth() + 1);
            //SetListview($('#page-Schedule').find('.ulItemList'), 'ScheduleList', "");
            SetListview($('#page-Schedule').find('.ulItemList'), SelectSvcMenu, "");
            isOffSet = false;
        }
        if (p.method == "set") { //  날짜를 선택하면 관련일자의 행사를 목록으로 표시
            //SetListview($('#page-Schedule').find('.ulItemList'), 'ScheduleList', p.value);
            SetListview($('#page-Schedule').find('.ulItemList'), SelectSvcMenu, p.value);
        }
    });

    $(this).find('#btnSearch').live("vclick", function () {
        var v_year = $("#schdate").data('datebox').theDate.getFullYear().toString();
        var v_month = ($("#schdate").data('datebox').theDate.getMonth() + 1);
        var v_day = $("#schdate").data('datebox').theDate.getDate().toString();
        if (v_month < 10) {
            v_strMonth = "0" + v_month;
        }
        var v_date = v_year + "-" + v_strMonth + "-" + v_day;
        SelectSvcMenu = $('#page-Schedule').find('.SelectAll .ui-btn-active').attr("SvcId");

        SetListview($('#page-Schedule').find('.ulItemList'), SelectSvcMenu, v_date);
    });

    $(this).find('.liScheduleList').live("vclick", function () {
        g_ContactView_q1 = $(this).attr('q1');

        $.mobile.changePage("/Utility/ScheduleModify.htm", { transition: _transition });
    });

});
/*$('#page-Schedule #btnAdd').live("vclick", function () {

    if ($('#page-ScheduleCreate') != undefined) {
        $('#page-ScheduleCreate').data("mode", "new");
    }

});*/
$('#page-Schedule').find('#aNew').live("vclick", function (evt) {

    var $page = $('#page-ScheduleCreate');


    $page.find("#txtTitle").val("");
    $page.find("#txtContact").val("")


    $.mobile.changePage("/Utility/ScheduleCreate.htm", { transition: _transition });
    $.mobile.pageLoading(true);

    $page.data("mode", "new");
});
$('#page-Schedule').find('.SelectAll a').live("vclick", function () {
    var today = new Date();
    GetScheduleMonthList(today.getFullYear(), today.getMonth() + 1);

    SelectSvcMenu = $('#page-Schedule').find('.SelectAll .ui-btn-active').attr("SvcId");
    SetListview($('#page-Schedule').find('.ulItemList'), SelectSvcMenu, "");
    $('#schdate').datebox('refresh');
});
$('#page-Schedule').live("pageshow", function () {
    var today = new Date();
    GetScheduleMonthList(today.getFullYear(), today.getMonth() + 1);
    $('#schdate').datebox('refresh');

   
    var v_year = today.getFullYear();
    var v_month = today.getMonth() + 1;
    var v_day = today.getDate();
    if (v_month < 10) {
        v_strMonth = "0" + v_month;
    }
    var v_date = v_year + "-" + v_strMonth + "-" + v_day;
    $("#schdate",$(this)).val(v_date);

    SelectSvcMenu = $('#page-Schedule').find('.SelectAll .ui-btn-active').attr("SvcId");

    SetListview($('#page-Schedule').find('.ulItemList'), SelectSvcMenu, v_date);

});

// 특정달의 행사를 달력에 상태표시
function GetScheduleMonthList(yy, mm) {
    var ScheduleSvcID;
    SelectSvcMenu = $('#page-Schedule').find('.SelectAll .ui-btn-active').attr("SvcId");
    if (SelectSvcMenu == "ScheduleList")
        ScheduleSvcID = "ScheduleMonthList";
    else
        ScheduleSvcID = "ScheduleMonthListMy";

    ScheduleMonth = undefined;    
    var Days = new Array();
    var pl = new JSONClientParameters();
    //pl.add("SvcID", "ScheduleMonthList");
    pl.add("SvcID", ScheduleSvcID);
    var pstr = "<DataTable><Record>";
    pstr += "<p1>" + yy + "</p1>";
    pstr += "<p2>" + mm + "</p2>";
    pstr += "<us>" + sm28 + "</us>";
    pstr += "</Record></DataTable>";
    pl.add("XmlParms", pstr);
    ScheduleMonth = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);

    if (ScheduleMonth == undefined) return false;
    var Rows = ScheduleMonth.Records.length;
    for (var i = 0; i < Rows; i++) {
        Days.push(ScheduleMonth.Records[i].dd);
    }
    $('#schdate').data('datebox').options.highDates = Days;

}
$('#page-ScheduleCreate').live("pageshow", function () {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    $('#page-ScheduleCreate').data("mode", "new");



    
});
//일정저장
$('#page-ScheduleCreate').live("pagecreate", function () {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";


    $('#selTime').html('');
    $('#selMinute').html('');
    $("#selTime").append("<option value='' selected='selected'>시간선택</option>");
    $("#selMinute").append("<option value='' selected='selected'>분선택</option>");

    var i;
    
    for (i = 1; i <= 24; i++) {
        var v_val;

        if (i < 10)
            v_val = "0" + i.toString();
        else if (i == 24)
            v_val = "00";
        else
            v_val = i.toString();


        $("#selTime").append("<option value='" + v_val + "'>" + i.toString() + "</option>");
    }
    var j = 0;
    for (i = 0; i <= 5; i++) {
        var v_val;

        if (j < 10)
            v_val = "0" + j.toString();
        else
            v_val = j.toString();

        $("#selMinute").append("<option value='" + v_val + "'>" + v_val + "</option>");

        j = j + 10;
    }

    var today = new Date();
    var v_year = today.getFullYear();
    var v_month = today.getMonth() + 1;
    var v_day = today.getDate();
    if (v_month < 10) {
        v_strMonth = "0" + v_month;
    }
    var v_date = v_year + "-" + v_strMonth + "-" + v_day;
    $("#schdate", $(this)).val(v_date);


});

$('#page-ScheduleCreate').find('.btnNewSchedule').live("vclick", function (evt) {

    try {
        _id = $('#page-ScheduleCreate');

        var v_year = $("#schdate", _id).data('datebox').theDate.getFullYear().toString();
        var v_month = ($("#schdate", _id).data('datebox').theDate.getMonth() + 1);
        var v_day = $("#schdate", _id).data('datebox').theDate.getDate().toString();
        var v_strMonth;

        if (v_month < 10) {
            v_strMonth = "0" + v_month;
        }
        var v_date = v_year + "-" + v_strMonth + "-" + v_day;
        var v_time = $('#selTime option:selected').val() + $('#selMinute option:selected').val();

        var pl = new JSONClientParameters();
        pl.add("SvcID", "ScheduleCreate");
        var pstr = "<DataTable><Record>";
        pstr += "<p1>" + $("#txtTitle",_id).val() + "</p1>";
        pstr += "<p2>" + v_date + "</p2>";
        pstr += "<p3>" + v_time + "</p3>";
        pstr += "<p4>" + $("#txtContact",_id).val() + "</p4>";
        pstr += "<p5>" + sm28.replace('T', '') + "</p5>";
        pstr += "<p6>0</p6>";
        pstr += "</Record></DataTable>";

        //alert("create pstr:" + pstr);
        pl.add("XmlParms", pstr);
        PostStrSync("/bzService/DBProxy.asmx/execRun", pl);

    }
    catch (e) {
        alert(e.toString());
    }
});

$('#page-ScheduleModify').live("pagecreate", function () {

    $('#page-ScheduleModify').find('.btnDelete').live("vclick", function (evt) {
        var q1 = getUrlVars()["q1"];
        var q2 = getUrlVars()["q2"];
        if (q1 == undefined) q1 = g_ContactView_q1;
        if (q2 == undefined) q2 = g_ContactView_q2;
        if (q1 == undefined || q1 == "") q1 = "0";
        if (q2 == undefined || q2 == "") q2 = "";

        var cfm = confirm("정말 삭제하시겠습니까?");

        if (cfm == true) {

            try {

                var pl = new JSONClientParameters();
                pl.add("SvcID", "ScheduleDelete");
                var pstr = "<DataTable><Record>";
                pstr += "<p1>" + q1 + "</p1>";
                pstr += "<p2></p2>";
                pstr += "<us>" + sm28.replace('T', '') + "</us>";
                pstr += "</Record></DataTable>";

                //alert("pstr:" + pstr);
                pl.add("XmlParms", pstr);
                PostStrSync("/bzService/DBProxy.asmx/execRun", pl);



            }
            catch (e) {
                alert(e.toString());
            }
        } else {
            return false;
        }

    });

});


$('#page-ScheduleModify').live("pageshow", function () {



    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    $('#page-ScheduleModify').data("mode", "edit");

    $(this).find("#txtTitle").val("");
    $(this).find("#txtContact").val("");


    SetValue($('#page-ScheduleModify').find('.DataUl'), 'ScheduleView', q1);


    var pl = new JSONClientParameters();
    pl.add("SvcID", "ScheduleView");
    var pstr = "<DataTable><Record>";
    pstr += "<p1>" + q1 + "</p1>";
    pstr += "<us>" + sm28 + "</us>";
    pstr += "</Record></DataTable>";
    pl.add("XmlParms", pstr);

    var _data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);

    if (_data == undefined) return false;
    var Rows = _data.Records.length;

    var _SCHUSER = _data.Records[0].SCHUSER;

    $("#txtTitle", $(this)).val(_data.Records[0].SCHNAME);
    $("#txtContact", $(this)).val(_data.Records[0].SCHDESC);

    if (_SCHUSER == sm28.replace("T", "")) {
        $(this).find('.btnModify').toggle(true);
        $(this).find('.btnDelete').toggle(true);
        $("#txtTitle", $(this)).readonly = true;
        $("#txtContact", $(this)).readonly = true;
    } else {
        $(this).find('.btnModify').toggle(false);
        $(this).find('.btnDelete').toggle(false);
        $("#txtTitle", $(this)).readonly = false;
        $("#txtContact", $(this)).readonly = false;
    }



});

$('#page-ScheduleModify').find('.btnModify').live("vclick", function (evt) {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    try {
        var _id = $('#page-ScheduleModify');

        var v_year = $("#schdate").data('datebox').theDate.getFullYear().toString();
        var v_month = ($("#schdate").data('datebox').theDate.getMonth() + 1);
        var v_day = $("#schdate").data('datebox').theDate.getDate().toString();

        var v_strMonth;

        if (v_month < 10) {
            v_strMonth = "0" + v_month;
        }
        var v_date = v_year + "-" + v_strMonth + "-" + v_day;
        var v_time = $('#selTime option:selected').val() + $('#selMinute option:selected').val();

        var pl = new JSONClientParameters();
        pl.add("SvcID", "ScheduleCreate");
        var pstr = "<DataTable><Record>";
        pstr += "<p1>" + $("#txtTitle", _id).val() + "</p1>";
        pstr += "<p2>" + $("#txtSchDate", _id)[0].innerHTML + "</p2>";
        pstr += "<p3>" + $("#txtSchTime", _id)[0].innerHTML.replace(':', '') + "</p3>";
        pstr += "<p4>" + $("#txtContact", _id).val() + "</p4>";
        pstr += "<p5>" + sm28.replace('T', '') + "</p5>";
        pstr += "<p6>" + q1 + "</p6>";
        pstr += "</Record></DataTable>";

        //alert("pstr:" + pstr);
        pl.add("XmlParms", pstr);
        PostStrSync("/bzService/DBProxy.asmx/execRun", pl);



    }
    catch (e) {
        alert(e.toString());
    }
});


// -------------------------------------------------------------------------------------------
// kh 거래처 등록
// -------------------------------------------------------------------------------------------
$('#page-AccountCreate').live("pageshow", function () {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined) q1 = $('#page-AccountView').data("q1");
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    $(this).find('#txtCLINAME').val("");
    $(this).find('#txtCALLNAME').val("");
    $(this).find('#txtTELNO1').val("");
    $(this).find('#txtTELNO2').val("");
    $(this).find('#txtTELNO3').val("");
    $(this).find('#txtMOBILE1').val("");
    $(this).find('#txtMOBILE2').val("");
    $(this).find('#txtMOBILE3').val("");
    $(this).find('#txtUPRADDRESS').val("");
    $(this).find('#txtLWRADDRESS').val("");
    $(this).find('#selCLIENTTYPE').val(0);
    $(this).find('#selCOMREASON').val(0);
    $(this).find('#txtDESCRIPTION').val("");

    
});

$('#page-AccountCreate').find('.btnSave').live("vclick", function (evt) {

    try {
        var $page = $('#page-AccountCreate');

        var v_CLINAME = $page.find('#txtCLINAME').val();

        if (v_CLINAME == "") { return false; }
        var v_CALLNAME = $page.find('#txtCALLNAME').val();
        var v_TELNO1 = $page.find('#txtTELNO1').val();
        var v_TELNO2 = $page.find('#txtTELNO2').val();
        var v_TELNO3 = $page.find('#txtTELNO3').val();
        var v_MOBILE1 = $page.find('#txtMOBILE1').val();
        var v_MOBILE2 = $page.find('#txtMOBILE2').val();
        var v_MOBILE3 = $page.find('#txtMOBILE3').val();
        var v_UPRADDRESS = $page.find('#txtUPRADDRESS').val();
        var v_LWRADDRESS = $page.find('#txtLWRADDRESS').val();
        var v_CLIENTTYPE = $page.find('#selCLIENTTYPE option:selected').val();
        var v_COMREASON = $page.find('#selCOMREASON option:selected').val();
        var v_DESCRIPTION = $page.find('#txtDESCRIPTION').val();

        var pl = new JSONClientParameters();
        pl.add("SvcID", "AccountCreate");
        var pstr = "<DataTable><Record>";
        pstr += "<p1><![CDATA[" + v_CLINAME + "]]></p1>";
        pstr += "<p2>" + v_CALLNAME + "</p2>";
        pstr += "<p3>" + v_TELNO1 + "</p3>";
        pstr += "<p4>" + v_TELNO2 + "</p4>";
        pstr += "<p5>" + v_TELNO3 + "</p5>";
        pstr += "<p6>" + v_MOBILE1 + "</p6>";
        pstr += "<p7>" + v_MOBILE2 + "</p7>";
        pstr += "<p8>" + v_MOBILE3 + "</p8>";
        pstr += "<p9><![CDATA[" + v_UPRADDRESS + "]]></p9>";
        pstr += "<p10><![CDATA[" + v_LWRADDRESS + "]]></p10>";
        pstr += "<p11>" + v_CLIENTTYPE + "</p11>";
        pstr += "<p12>" + v_COMREASON + "</p12>";
        pstr += "<p13></p13>";
        pstr += "<p14><![CDATA[" + v_DESCRIPTION + "]]></p14>";
        pstr += "<us>" + sm28.replace("T", "") + "</us>";
        pstr += "</Record></DataTable>";


        pl.add("XmlParms", pstr);
        PostStrSync("/bzService/DBProxy.asmx/execRun", pl);

        //alert("pstr:" + pstr);

    }
    catch (e) {
        alert(e.toString());
    }

});

// -------------------------------------------------------------------------------------------
// kh 고객 등록
// -------------------------------------------------------------------------------------------
$('#page-ContactCreateCus').find('#aSearch').live("vclick", function (evt) {
    //$('#page-ContactCreateCus').trigger('pageshow');

    $('#page-PopupAccount').data("spage", "ContactCreateCus");
    $('#page-PopupAccount').data("url", "/Account/ContactCreateCus.html");

    g_cursPage = "ContactCreateCus";
    g_cursUrl = "/Account/ContactCreateCus.html";
});

$('#page-ContactCreateCus').live("pageshow", function () {

    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined && $(this).data("mode") == "edit") q1 = $('#page-ContactView').data("q1");
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    if (q1 == "0" || q1 == undefined || $(this).data("mode") =="new") {
        $(this).find('.btnSave').toggle(true);
        $(this).find('.btnModify').toggle(false);
        $(this).find('.btnDelete').toggle(false);

        

    } else {
        $(this).find('.btnSave').toggle(false);
        $(this).find('.btnModify').toggle(true);
        $(this).find('.btnDelete').toggle(true);





        var pl = new JSONClientParameters();
        pl.add("SvcID", "ContactView");
        var pstr = "<DataTable><Record>";
        pstr += "<p1>" + q1 + "</p1>";
        pstr += "<us>" + sm28 + "</us>";
        pstr += "</Record></DataTable>";
        pl.add("XmlParms", pstr);

        var _data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);

        if (_data == undefined) return false;
        var Rows = _data.Records.length;

        var _CSTNAME = _data.Records[0].CSTNAME;
        var _COMPANY = _data.Records[0].COMPANY;
        var _WRKTEL1 = _data.Records[0].WRKTEL1;
        var _WRKTEL2 = _data.Records[0].WRKTEL2;
        var _WRKTEL3 = _data.Records[0].WRKTEL3;
        var _MOBILE1 = _data.Records[0].MOBILE1;
        var _MOBILE2 = _data.Records[0].MOBILE2;
        var _MOBILE3 = _data.Records[0].MOBILE3;
        var _WRKFAXTEL1 = _data.Records[0].WRKFAXTEL1;
        var _WRKFAXTEL2 = _data.Records[0].WRKFAXTEL2;
        var _WRKFAXTEL3 = _data.Records[0].WRKFAXTEL3;
        var _EMAIL = _data.Records[0].EMAIL;
        var _WRKUPRADDRESS = _data.Records[0].WRKUPRADDRESS;
        var _WRKLWRADDRESS = _data.Records[0].WRKLWRADDRESS;
        var _CLIENTTYPE = _data.Records[0].CLIENTTYPE;


        $(this).find('#txtCSTNAME').val(_CSTNAME);
        $(this).find('#txtCOMPANY').val(_COMPANY);
        $(this).find('#txtWRKTEL1').val(_WRKTEL1);
        $(this).find('#txtWRKTEL2').val(_WRKTEL2);
        $(this).find('#txtWRKTEL3').val(_WRKTEL3);
        $(this).find('#txtMOBILE1').val(_MOBILE1);
        $(this).find('#txtMOBILE2').val(_MOBILE2);
        $(this).find('#txtMOBILE3').val(_MOBILE3);
        $(this).find('#txtWRKFAXTEL1').val(_WRKFAXTEL1);
        $(this).find('#txtWRKFAXTEL2').val(_WRKFAXTEL2);
        $(this).find('#txtWRKFAXTEL3').val(_WRKFAXTEL3);
        $(this).find('#txtEMAIL').val(_EMAIL);
        $(this).find('#txtWRKUPRADDRESS').val(_WRKUPRADDRESS);
        $(this).find('#txtWRKLWRADDRESS').val(_WRKLWRADDRESS);
        //$(this).find('#selCLIENTTYPE').val(_CLIENTTYPE);

        $("#page-ContactCreateCus #selCLIENTTYPE option").removeAttr("selected");
        $("#page-ContactCreateCus #selCLIENTTYPE option[value='" + _CLIENTTYPE + "']").attr("selected", true);
        $("#page-ContactCreateCus #selCLIENTTYPE").parent().find(".ui-btn-text").html($("#page-ContactCreateCus #selCLIENTTYPE option:selected").text());


    }

});
$('#page-ContactCreateCus').find('.btnSave').live("vclick", function (evt) {

    try {
        var $page = $('#page-ContactCreateCus');

        var v_CSTNAME = $page.find('#txtCSTNAME').val();

        if (v_CSTNAME == "") { return false; }
        var v_CLIID = $page.find('#txtCLIID').val();
        var v_COMPANY = $page.find('#txtCOMPANY').val();
        var v_WRKTEL1 = $page.find('#txtWRKTEL1').val();
        var v_WRKTEL2 = $page.find('#txtWRKTEL2').val();
        var v_WRKTEL3 = $page.find('#txtWRKTEL3').val();
        var v_MOBILE1 = $page.find('#txtMOBILE1').val();
        var v_MOBILE2 = $page.find('#txtMOBILE2').val();
        var v_MOBILE3 = $page.find('#txtMOBILE3').val();
        var v_WRKFAXTEL1 = $page.find('#txtWRKFAXTEL1').val();
        var v_WRKFAXTEL2 = $page.find('#txtWRKFAXTEL2').val();
        var v_WRKFAXTEL3 = $page.find('#txtWRKFAXTEL3').val();
        var v_EMAIL = $page.find('#txtEMAIL').val();
        var v_WRKUPRADDRESS = $page.find('#txtWRKUPRADDRESS').val();
        var v_WRKLWRADDRESS = $page.find('#txtWRKLWRADDRESS').val();
        var v_CLIENTTYPE = $page.find('#selCLIENTTYPE option:selected').val();

        var pl = new JSONClientParameters();
        pl.add("SvcID", "ContactCreate");
        var pstr = "<DataTable><Record>";
        pstr += "<p1>" + v_CSTNAME + "</p1>"; //고객명
        pstr += "<p2>" + v_CLIID + "</p2>"; //거래처 번호
        pstr += "<p3>" + v_COMPANY + "</p3>";
        pstr += "<p4>" + v_WRKTEL1 + "</p4>";
        pstr += "<p5>" + v_WRKTEL2 + "</p5>";
        pstr += "<p6>" + v_WRKTEL3 + "</p6>";
        pstr += "<p7>" + v_MOBILE1 + "</p7>";
        pstr += "<p8>" + v_MOBILE2 + "</p8>";
        pstr += "<p9>" + v_MOBILE3 + "</p9>";
        pstr += "<p10>" + v_WRKFAXTEL1 + "</p10>";
        pstr += "<p11>" + v_WRKFAXTEL2 + "</p11>";
        pstr += "<p12>" + v_WRKFAXTEL3 + "</p12>";
        pstr += "<p13>" + v_EMAIL + "</p13>";
        pstr += "<p14>" + v_WRKUPRADDRESS + "</p14>";
        pstr += "<p15>" + v_WRKLWRADDRESS + "</p15>";
        pstr += "<p16>" + "</p16>";
        pstr += "<p17>" + v_CLIENTTYPE + "</p17>";
        pstr += "<us>" + sm28.replace("T", "") + "</us>";
        pstr += "</Record></DataTable>";

        //alert("pstr:" + pstr);
        pl.add("XmlParms", pstr);
        PostStrSync("/bzService/DBProxy.asmx/execRun", pl, function (evt) {


        });

        //alert("pstr:" + pstr);

    }
    catch (e) {
        alert(e.toString());
    }

});

$('#page-ContactCreateCus').find('.btnModify').live("vclick", function (evt) {

    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined) q1 = $('#page-ContactView').data("q1");
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    try {
        var $page = $('#page-ContactCreateCus');

        var v_CSTNAME = $page.find('#txtCSTNAME').val();

        if (v_CSTNAME == "") { return false; }
        var v_CLIID = $page.find('#txtCLIID').val();
        var v_COMPANY = $page.find('#txtCOMPANY').val();
        var v_WRKTEL1 = $page.find('#txtWRKTEL1').val();
        var v_WRKTEL2 = $page.find('#txtWRKTEL2').val();
        var v_WRKTEL3 = $page.find('#txtWRKTEL3').val();
        var v_MOBILE1 = $page.find('#txtMOBILE1').val();
        var v_MOBILE2 = $page.find('#txtMOBILE2').val();
        var v_MOBILE3 = $page.find('#txtMOBILE3').val();
        var v_WRKFAXTEL1 = $page.find('#txtWRKFAXTEL1').val();
        var v_WRKFAXTEL2 = $page.find('#txtWRKFAXTEL2').val();
        var v_WRKFAXTEL3 = $page.find('#txtWRKFAXTEL3').val();
        var v_EMAIL = $page.find('#txtEMAIL').val();
        var v_WRKUPRADDRESS = $page.find('#txtWRKUPRADDRESS').val();
        var v_WRKLWRADDRESS = $page.find('#txtWRKLWRADDRESS').val();
        var v_CLIENTTYPE = $page.find('#selCLIENTTYPE option:selected').val();

        var pl = new JSONClientParameters();
        pl.add("SvcID", "ContactCreate");
        var pstr = "<DataTable><Record>";
        pstr += "<p1>" + v_CSTNAME + "</p1>"; //고객명
        pstr += "<p2>" + v_CLIID + "</p2>"; //거래처 번호
        pstr += "<p3>" + v_COMPANY + "</p3>";
        pstr += "<p4>" + v_WRKTEL1 + "</p4>";
        pstr += "<p5>" + v_WRKTEL2 + "</p5>";
        pstr += "<p6>" + v_WRKTEL3 + "</p6>";
        pstr += "<p7>" + v_MOBILE1 + "</p7>";
        pstr += "<p8>" + v_MOBILE2 + "</p8>";
        pstr += "<p9>" + v_MOBILE3 + "</p9>";
        pstr += "<p10>" + v_WRKFAXTEL1 + "</p10>";
        pstr += "<p11>" + v_WRKFAXTEL2 + "</p11>";
        pstr += "<p12>" + v_WRKFAXTEL3 + "</p12>";
        pstr += "<p13>" + v_EMAIL + "</p13>";
        pstr += "<p14>" + v_WRKUPRADDRESS + "</p14>";
        pstr += "<p15>" + v_WRKLWRADDRESS + "</p15>";
        pstr += "<p16>" + q1 + "</p16>";
        pstr += "<p17>" + v_CLIENTTYPE + "</p17>";
        pstr += "<us>" + sm28.replace("T", "") + "</us>";
        pstr += "</Record></DataTable>";

        //alert("pstr:" + pstr);
        pl.add("XmlParms", pstr);
        PostStrSync("/bzService/DBProxy.asmx/execRun", pl, function (evt) {


        });

        

    }
    catch (e) {
        alert(e.toString());
    }


});


// -------------------------------------------------------------------------------------------
// kh 거래처 등록
// -------------------------------------------------------------------------------------------
/*
$('#page-ScheduleModify').live("pagecreate", function () {

    $('#page-ScheduleModify').find('.btnDelete').live("vclick", function (evt) {
        var q1 = getUrlVars()["q1"];
        var q2 = getUrlVars()["q2"];
        if (q1 == undefined) q1 = g_ContactView_q1;
        if (q2 == undefined) q2 = g_ContactView_q2;
        if (q1 == undefined) q1 = $('#page-AccountView').data("q1");
        if (q1 == undefined || q1 == "") q1 = "0";
        if (q2 == undefined || q2 == "") q2 = "";

        var cfm = confirm("정말 삭제하시겠습니까?");

        if (cfm == true) {

            try {

                var pl = new JSONClientParameters();
                pl.add("SvcID", "AccountDelete");
                var pstr = "<DataTable><Record>";
                pstr += "<p1>" + q1 + "</p1>";
                pstr += "<p2></p2>";
                pstr += "<us>" + sm28.replace('T', '') + "</us>";
                pstr += "</Record></DataTable>";

                //alert("pstr:" + pstr);
                pl.add("XmlParms", pstr);
                PostStrSync("/bzService/DBProxy.asmx/execRun", pl);



            }
            catch (e) {
                alert(e.toString());
            }
        } else {
            return false;
        }

    });
});*/

$('#page-AccountModify').live("pageshow", function () {



    var q1 = $('#page-AccountView').data("q1"); // getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_AccountView_q1;
    if (q2 == undefined) q2 = g_AccountView_q2;
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";


    //SetValue($('#page-AccountModify').find('.DataUl'), 'AccountView', q1);


    var pl = new JSONClientParameters();
    pl.add("SvcID", "AccountView");
    var pstr = "<DataTable><Record>";
    pstr += "<p1>" + q1 + "</p1>";
    pstr += "<us>" + sm28 + "</us>";
    pstr += "</Record></DataTable>";
    pl.add("XmlParms", pstr);

    var _data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);

    if (_data == undefined) return false;
    var Rows = _data.Records.length;

    if (Rows > 0) {
        var _OWNER = _data.Records[0].OWNER;
        var _CLINAME = _data.Records[0].CLINAME;
        var _CALLNAME = _data.Records[0].CALLNAME;
        var _TELNO1 = _data.Records[0].TELNO1;
        var _TELNO2 = _data.Records[0].TELNO2;
        var _TELNO3 = _data.Records[0].TELNO3;
        var _MOBILE1 = _data.Records[0].MOBILE1;
        var _MOBILE2 = _data.Records[0].MOBILE2;
        var _MOBILE3 = _data.Records[0].MOBILE3;
        var _UPRADDRESS = _data.Records[0].UPRADDRESS;
        var _LWRADDRESS = _data.Records[0].LWRADDRESS;
        var _CLIENTTYPE = _data.Records[0].CLIENTTYPE;
        var _COMREASON = _data.Records[0].COMREASON;
        var _DESCRIPTION = _data.Records[0].DESCRIPTION;

        $(this).find('#txtCLINAME').val(_CLINAME);
        $(this).find('#txtCALLNAME').val(_CALLNAME);
        $(this).find('#txtTELNO1').val(_TELNO1);
        $(this).find('#txtTELNO2').val(_TELNO2);
        $(this).find('#txtTELNO3').val(_TELNO3);
        $(this).find('#txtMOBILE1').val(_MOBILE1);
        $(this).find('#txtMOBILE2').val(_MOBILE2);
        $(this).find('#txtMOBILE3').val(_MOBILE3);
        $(this).find('#txtUPRADDRESS').val(_UPRADDRESS);
        $(this).find('#txtLWRADDRESS').val(_LWRADDRESS);
        $(this).find('#txtDESCRIPTION').val(_DESCRIPTION);

        //$(this).find('#selCLIENTTYPE').val(_CLIENTTYPE);
        //$(this).find('#selCOMREASON').val(_COMREASON);

        $("#page-AccountModify #selCLIENTTYPE option").removeAttr("selected");
        $("#page-AccountModify #selCLIENTTYPE option[value='" + _CLIENTTYPE + "']").attr("selected", true);
        $("#page-AccountModify #selCLIENTTYPE").parent().find(".ui-btn-text").html($("#page-AccountModify #selCLIENTTYPE option:selected").text());

        $("#page-AccountModify #selCOMREASON option").removeAttr("selected");
        $("#page-AccountModify #selCOMREASON option[value='" + _COMREASON + "']").attr("selected", true);
        $("#page-AccountModify #selCOMREASON").parent().find(".ui-btn-text").html($("#page-AccountModify #selCOMREASON option:selected").text());


        if (_OWNER == sm28.replace("T", "")) {
            $(this).find('.btnModify').toggle(true);
            $(this).find('.btnDelete').toggle(true);
        } else {
            $(this).find('.btnModify').toggle(false);
            $(this).find('.btnDelete').toggle(false);
        }
    }



    $('#page-AccountModify').find('.btnModify').live("vclick", function (evt) {

        var q1 = getUrlVars()["q1"];
        var q2 = getUrlVars()["q2"];
        //if (q1 == undefined) q1 = g_ContactView_q1;
        //if (q2 == undefined) q2 = g_ContactView_q2;
        if (q1 == undefined) q1 = g_AccountView_q1;
        if (q2 == undefined) q2 = g_AccountView_q2;
        if (q1 == undefined) q1 = $('#page-AccountView').data("q1");
        if (q1 == undefined || q1 == "") q1 = "0";
        if (q2 == undefined || q2 == "") q2 = "";

        try {
            var $page = $('#page-AccountModify');

            var v_CLINAME = $page.find('#txtCLINAME').val();

            if (v_CLINAME == "") { return false; }
            var v_CALLNAME = $page.find('#txtCALLNAME').val();
            var v_TELNO1 = $page.find('#txtTELNO1').val();
            var v_TELNO2 = $page.find('#txtTELNO2').val();
            var v_TELNO3 = $page.find('#txtTELNO3').val();
            var v_MOBILE1 = $page.find('#txtMOBILE1').val();
            var v_MOBILE2 = $page.find('#txtMOBILE2').val();
            var v_MOBILE3 = $page.find('#txtMOBILE3').val();
            var v_UPRADDRESS = $page.find('#txtUPRADDRESS').val();
            var v_LWRADDRESS = $page.find('#txtLWRADDRESS').val();
            var v_CLIENTTYPE = $page.find('#selCLIENTTYPE').val();
            var v_COMREASON = $page.find('#selCOMREASON').val();
            var v_DESCRIPTION = $page.find('#txtDESCRIPTION').val();

            var pl = new JSONClientParameters();
            pl.add("SvcID", "AccountCreate");
            var pstr = "<DataTable><Record>";
            pstr += "<p1>" + v_CLINAME + "</p1>";
            pstr += "<p2>" + v_CALLNAME + "</p2>";
            pstr += "<p3>" + v_TELNO1 + "</p3>";
            pstr += "<p4>" + v_TELNO2 + "</p4>";
            pstr += "<p5>" + v_TELNO3 + "</p5>";
            pstr += "<p6>" + v_MOBILE1 + "</p6>";
            pstr += "<p7>" + v_MOBILE2 + "</p7>";
            pstr += "<p8>" + v_MOBILE3 + "</p8>";
            pstr += "<p9>" + v_UPRADDRESS + "</p9>";
            pstr += "<p10>" + v_LWRADDRESS + "</p10>";
            pstr += "<p11>" + v_CLIENTTYPE + "</p11>";
            pstr += "<p12>" + v_COMREASON + "</p12>";
            pstr += "<p13>" + q1 + "</p13>";
            pstr += "<p14>" + v_DESCRIPTION + "</p14>";
            pstr += "<us>" + sm28.replace("T", "") + "</us>";
            pstr += "</Record></DataTable>";


            pl.add("XmlParms", pstr);
            PostStrSync("/bzService/DBProxy.asmx/execRun", pl, function (evt) {


            });

            //alert("pstr:" + pstr);

        }
        catch (e) {
            alert(e.toString());
        }

    });




});


// -------------------------------------------------------------------------------------------
// Todo
// -------------------------------------------------------------------------------------------
//서비스
$('#page-TodoList').live("pageshow", function () {

    var SelectSvcMenu = $('#page-TodoList').find('.SelectAll .ui-btn-active').attr("SvcId");
    SetListview($('#page-TodoList').find('.ulTodoList'), SelectSvcMenu, "");

});
$('#page-TodoList').find('.btnsearch').live("vclick", function (evt) {
    var $page = $('#page-TodoList');

    g_ContactView_q2 = $page.find(".txtsearch").val();
    var SelectSvcMenu = $page.find('.SelectAll .ui-btn-active').attr("SvcId");
    SetListview($page.find('.ulTodoList'), SelectSvcMenu, g_ContactView_q2);
});

$('#page-TodoList').find('.liJobList').live("vclick", function (evt) {
    $.mobile.pageLoading();
    g_ContactView_q1 = $(this).attr('q1');
    $.mobile.changePage("/Utility/TodoView.html", { transition: _transition });
    $.mobile.pageLoading(true);
});

$('#page-TodoView').live("pageshow", function () {

    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined) q1 = "0";
    if (q2 == undefined) q2 = "";

    $('#page-TodoView').find(".txtsearch").val(q2);
    $('#page-TodoView').data("q1", q1);

    if ($('#page-TodoView').data("q1") != undefined)
        q1 = $('#page-TodoView').data("q1");

    SetValue($('#page-TodoView').find('.DataUl'), 'JobView', q1);


    //참여직원
    SetListview($('#page-TodoView .ulMemberList'), "JobMemberList", q1);

    //참여고객
    SetListview($('#page-TodoView .ulUserList'), "JobUserList", q1);

});

$('#page-TodoView').live("pagecreate", function () {


    $(this).find('.btnsearch').live("vclick", function (evt) {
        var SelectSvcMenu = $('#page-TodoView').find('.SelectAll .ui-btn-active').attr("SvcId");

        SetListview($('#page-TodoView').find('.ulMainList'), SelectSvcMenu, $('#page-TodoView').find(".txtsearch").val());
    });

    //우측목록 검색클릭동작시 
    $(this).find('.liJobList').live("vclick", function (evt) {
        g_ContactView_q1 = $(this).attr('q1');

        SetValue($('#page-TodoView').find('.DataUl'), "JobView", g_ContactView_q1);



        //참여직원
        SetListview($('#page-TodoView .ulMemberList'), "JobMemberList", g_ContactView_q1);

        //참여고객
        SetListview($('#page-TodoView .ulUserList'), "JobUserList", g_ContactView_q1);

        window.scrollTo(0, 0);
    });

    $(this).find('.liUserList').live("vclick", function (evt) {
        $.mobile.pageLoading();

        g_ContactView_q1 = $(this).attr('q1');
        $.mobile.changePage("/Account/ContactView.html", { transition: _transition });
        $.mobile.pageLoading(true);
    });


});


/*
$('#page-TodoList').live("pagecreate", function () {
GetTodoList($(this).find('.ulTodoList'), "");

$(this).find('.btnsearch').live("vclick", function (evt) {
GetTodoList($('#page-TodoList').find('.ulTodoList'), $('#page-TodoList').find(".txtsearch").val());
});
});

function GetTodoList(obj, a) {
obj.html("").listview("destroy").listview();
var pl = new JSONClientParameters();
// pl.add("q1", a);
g_ContactView_q2 = a;
pl.add("SvcID", "Svc08");
pl.add("XmlParms", "<DataTable><Record><p1>" + a + "</p1></Record></DataTable>");
// PostJsonData("/Account/Contact.asmx/Find", pl, function (data) {
PostJsonData("/bzService/DBProxy.asmx/execComm", pl, function (data) {

if (data.TRCOUNT > 0) {
var Rows = data.Records.length;
for (var i = 0; i < Rows; i++) {
var DataRow = data.Records[i];

var _html = "";
_html += "<li><a href='#' q1='" + DataRow.OPRID + "' class='liTodoList'>";
_html += "<h3>" + DataRow.OPRNAME + "</h3>";
_html += "<p><strong>" + DataRow.STARTDATE + ' / ' + DataRow.ENDDATE + "</strong></p>";
_html += "<p>" + DataRow.OPRDESC + " </p>";
_html += "<p class='ui-li-aside'><strong>" + DataRow.PROGRATIO + "</strong></p>";
_html += "</a></li>";
// OPRID, OPRNAME, OPRDESC, PROGRATIO, STARTDATE, ENDDATE
obj.append(_html); //data.TRCOUNT);ContactView.html
}

obj.listview("destroy").listview();

obj.find('.liContactList').live("vclick", function (evt) {
g_ContactView_q1 = $(this).attr('q1');
$.mobile.changePage("/Account/ContactView.html", {
transition: _transition
});
});

}

});
}
*/

// -------------------------------------------------------------------------------------------
// Opportunity
// -------------------------------------------------------------------------------------------
$('#page-OpportunityView').live("pagecreate", function () {

    //삭제
    $('#page-OpportunityView').find('.btnDelete').live("vclick", function (evt) {
        var q1 = getUrlVars()["q1"];
        var q2 = getUrlVars()["q2"];
        if (q1 == undefined) q1 = g_ContactView_q1;
        if (q2 == undefined) q2 = g_ContactView_q2;
        if (q1 == undefined) q1 = $('#page-OpportunityView').data("q1");
        if (q1 == undefined || q1 == "") q1 = "0";
        if (q2 == undefined || q2 == "") q2 = "";

        var cfm = confirm("정말 삭제하시겠습니까?");

        if (cfm == true) {
            try {

                var pl = new JSONClientParameters();
                pl.add("SvcID", "OpportunityDelete");
                var pstr = "<DataTable><Record>";
                pstr += "<p1>" + q1 + "</p1>";
                pstr += "<p2></p2>";
                pstr += "<us>" + sm28.replace('T', '') + "</us>";
                pstr += "</Record></DataTable>";

                //alert("pstr:" + pstr);
                pl.add("XmlParms", pstr);
                PostStrSync("/bzService/DBProxy.asmx/execRun", pl);


                $.mobile.changePage("/Opportunity/OpportunityList.html", { transition: _transition });

            }
            catch (e) {
                alert(e.toString());
            }
        } else {
            return false;
        }

    });
});
//영업등록
$('#page-OpportunityModify').live("pageshow", function () {

    var q1 = $('#page-OpportunityView').data("q1"); //getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    //if (q1 == undefined) q1 = $('#page-OpportunityView').data("q1");
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    if (q1 == "0" || q1 == undefined || $(this).data("mode") == "new") {
        $(this).find('.btnSave').toggle(true);
        $(this).find('.btnModify').toggle(false);
        $(this).find('.btnDelete').toggle(false);



    } else {
        $(this).find('.btnSave').toggle(false);
        $(this).find('.btnModify').toggle(true);
        $(this).find('.btnDelete').toggle(true);





        var pl = new JSONClientParameters();
        pl.add("SvcID", "OpportunityView");
        var pstr = "<DataTable><Record>";
        pstr += "<p1>" + q1 + "</p1>";
        pstr += "<us>" + sm28 + "</us>";
        pstr += "</Record></DataTable>";
        pl.add("XmlParms", pstr);

        var _data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);

        if (_data == undefined) return false;
        var Rows = _data.Records.length;

        var _OWNER = _data.Records[0].OWNER;

        if (_OWNER == sm28.replace("T", "")) {
            $(this).find('.btnModify').toggle(true);
            $(this).find('.btnDelete').toggle(true);
        } else {
            $(this).find('.btnModify').toggle(false);
            $(this).find('.btnDelete').toggle(false);
        }

        var _CLIID_NM = _data.Records[0].CLIID_;
        var _CLIID = _data.Records[0].CLIID;
        var _CALLNAME = _data.Records[0].CALLNAME;
        var _ADDRESS = _data.Records[0].ADDRESS;
        var _TELNO1 = _data.Records[0].TELNO1;
        var _TELNO2 = _data.Records[0].TELNO2;
        var _TELNO3 = _data.Records[0].TELNO3;
        var _SALENAME = _data.Records[0].SALENAME;
        var _SALESTATE = _data.Records[0].SALESTATE;
        var _STATEDATE = _data.Records[0].STATEDATE;
        var _PROB = _data.Records[0].PROB;
        var _FORDDATE = _data.Records[0].FORDDATE;
        var _NEED = _data.Records[0].NEED;
        var _SOLUTION = _data.Records[0].SOLUTION;
        var _CSTDESC = _data.Records[0].CSTDESC;
        var _FORDAMOUNT = _data.Records[0].FORDAMOUNT;

        $(this).find('#txtCOMPANY').val(_CLIID_NM);
        $(this).find('#txtCLIID').val(_CLIID);
        $(this).find('#txtCALLNAME').val(_CALLNAME);
        $(this).find('#txtADDRESS').val(_ADDRESS);
        $(this).find('#txtTELNO1').val(_TELNO1);
        $(this).find('#txtTELNO2').val(_TELNO2);
        $(this).find('#txtTELNO3').val(_TELNO3);
        $(this).find('#txtSALENAME').val(_SALENAME);
        $(this).find('#selSALESTATE').val(_SALESTATE);
        $(this).find('#dtSTATEDATE').val(_STATEDATE);
        $(this).find('#txtPROB').val(_PROB);
        $(this).find('#dtFORDDATE').val(_FORDDATE);
        $(this).find('#txtNEED').val(_NEED);
        $(this).find('#txtSOLUTION').val(_SOLUTION);
        $(this).find('#txtCSTDESC').val(_CSTDESC);
        $(this).find('#txtFORDAMOUNT').val(_FORDAMOUNT);

    }

});

$('#page-OpportunityModify').find('.btnModify').live("vclick", function (evt) {


    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined) q1 = $('#page-OpportunityView').data("q1");
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    try {
        var $page = $('#page-OpportunityModify');



        var v_CLIIDNM = $page.find('#txtCOMPANY').val();
        var v_CLIID = $page.find('#txtCLIID').val();
        if (v_CLIID == "" || v_CLIID == undefined) {
            return false;
        }
        var v_CALLNAME = $page.find('#txtCALLNAME').val();
        var v_UPRADDRESS = ""; // $page.find('#txtUPRADDRESS').val();
        var v_LWRADDRESS = ""; //$page.find('#txtLWRADDRESS').val();
        var v_TELNO1 = ""; // $page.find('#txtTELNO1').val();
        var v_TELNO2 = ""; // $page.find('#txtTELNO2').val();
        var v_TELNO3 = ""; // $page.find('#txtTELNO3').val();
        var v_SALENAME = $page.find('#txtSALENAME').val();
        var v_SALESTATE = $page.find('#selSALESTATE').val();
        var v_STATEDATE = $page.find('#dtSTATEDATE')[0].value;
        var v_PROB = $page.find('#txtPROB').val();
        var v_FORDDATE = $page.find('#dtFORDDATE')[0].value;
        var v_NEED = $page.find('#txtNEED').val();
        var v_SOLUTION = $page.find('#txtSOLUTION').val();
        var v_CSTDESC = $page.find('#txtCSTDESC').val();
        var v_FORDAMOUNT = $page.find('#txtFORDAMOUNT').val();

        var pl = new JSONClientParameters();
        pl.add("SvcID", "OpportunityCreate");
        var pstr = "<DataTable><Record>";
        pstr += "<p1>" + v_CLIIDNM + "</p1>"; //거래처명
        pstr += "<p2>" + v_CLIID + "</p2>"; //거래처 번호
        pstr += "<p3>" + v_CALLNAME + "</p3>";
        pstr += "<p4>" + v_UPRADDRESS + "</p4>"; //주소
        pstr += "<p5>" + v_LWRADDRESS + "</p5>"; //상세주소
        pstr += "<p6>" + v_TELNO1 + "</p6>";
        pstr += "<p7>" + v_TELNO2 + "</p7>";
        pstr += "<p8>" + v_TELNO3 + "</p8>";
        pstr += "<p9>" + v_SALENAME + "</p9>";
        pstr += "<p10>" + v_SALESTATE + "</p10>";
        pstr += "<p11>" + v_STATEDATE + "</p11>";
        pstr += "<p12>" + v_PROB + "</p12>";
        pstr += "<p13>" + v_FORDDATE + "</p13>";
        pstr += "<p14>" + v_NEED + "</p14>";
        pstr += "<p15>" + v_SOLUTION + "</p15>";
        pstr += "<p16>" + v_CSTDESC + "</p16>";
        pstr += "<p17>" + q1 + "</p17>";
        pstr += "<p18>" + v_FORDAMOUNT + "</p18>";
        pstr += "<us>" + sm28.replace("T", "") + "</us>";
        pstr += "</Record></DataTable>";

        //alert("pstr:" + pstr);
        pl.add("XmlParms", pstr);
        PostStrSync("/bzService/DBProxy.asmx/execRun", pl, function (evt) {


        });

        //alert("pstr:" + pstr);

    }
    catch (e) {
        alert(e.toString());
    }

});

$('#page-OpportunityCreate').find('.btnSave').live("vclick", function (evt) {

    try {
        var $page = $('#page-OpportunityCreate');



        var v_CLIIDNM = $page.find('#txtCOMPANY').val();
        var v_CLIID = $page.find('#txtCLIID').val();
        if (v_CLIID == "" || v_CLIID == undefined) {
            return false;
        }
        var v_CALLNAME = $page.find('#txtCALLNAME').val();
        var v_UPRADDRESS = ""; // $page.find('#txtUPRADDRESS').val();
        var v_LWRADDRESS = ""; //$page.find('#txtLWRADDRESS').val();
        var v_TELNO1 = ""; // $page.find('#txtTELNO1').val();
        var v_TELNO2 = ""; // $page.find('#txtTELNO2').val();
        var v_TELNO3 = ""; // $page.find('#txtTELNO3').val();
        var v_SALENAME = $page.find('#txtSALENAME').val();
        var v_SALESTATE = $page.find('#selSALESTATE').val();
        var v_STATEDATE = $page.find('#dtSTATEDATE')[0].value;
        var v_PROB = $page.find('#txtPROB').val();
        var v_FORDDATE = $page.find('#dtFORDDATE')[0].value;
        var v_NEED = $page.find('#txtNEED').val();
        var v_SOLUTION = $page.find('#txtSOLUTION').val();
        var v_CSTDESC = $page.find('#txtCSTDESC').val();
        var v_FORDAMOUNT = $page.find('#txtFORDAMOUNT').val();


        var pl = new JSONClientParameters();
        pl.add("SvcID", "OpportunityCreate");
        var pstr = "<DataTable><Record>";
        pstr += "<p1>" + v_CLIIDNM + "</p1>"; //거래처명
        pstr += "<p2>" + v_CLIID + "</p2>"; //거래처 번호
        pstr += "<p3>" + v_CALLNAME + "</p3>";
        pstr += "<p4>" + v_UPRADDRESS + "</p4>"; //주소
        pstr += "<p5>" + v_LWRADDRESS + "</p5>"; //상세주소
        pstr += "<p6>" + v_TELNO1 + "</p6>";
        pstr += "<p7>" + v_TELNO2 + "</p7>";
        pstr += "<p8>" + v_TELNO3 + "</p8>";
        pstr += "<p9>" + v_SALENAME + "</p9>";
        pstr += "<p10>" + v_SALESTATE + "</p10>";
        pstr += "<p11>" + v_STATEDATE + "</p11>";
        pstr += "<p12>" + v_PROB + "</p12>";
        pstr += "<p13>" + v_FORDDATE + "</p13>";
        pstr += "<p14>" + v_NEED + "</p14>";
        pstr += "<p15>" + v_SOLUTION + "</p15>";
        pstr += "<p16>" + v_CSTDESC + "</p16>";
        pstr += "<p17>" + "</p17>";
        pstr += "<p18>" + v_FORDAMOUNT + "</p18>";
        pstr += "<us>" + sm28.replace("T", "") + "</us>";
        pstr += "</Record></DataTable>";

        //alert("pstr:" + pstr);
        pl.add("XmlParms", pstr);
        PostStrSync("/bzService/DBProxy.asmx/execRun", pl, function (evt) {


        });

        //alert("pstr:" + pstr);

    }
    catch (e) {
        alert(e.toString());
    }

});

$('#page-OpportunityCreate').find('#aSearch').live("vclick", function (evt) {
   

    $('#page-PopupAccount').data("spage", "OpportunityCreate");
    $('#page-PopupAccount').data("url", "/Opportunity/OpportunityCreate.html");

    g_cursPage = "OpportunityCreate";
    g_cursUrl = "/Opportunity/OpportunityCreate.html";


});
$('#page-OpportunityModify').find('#aSearch').live("vclick", function (evt) {


    $('#page-PopupAccount').data("spage", "OpportunityModify");
    $('#page-PopupAccount').data("url", "/Opportunity/OpportunityModify.html");

    g_cursPage = "OpportunityModify";
    g_cursUrl = "/Opportunity/OpportunityModify.html";


});


$('#page-OpportunityList').live("pagecreate", function () {

    $(this).find('.btnsearch').live("vclick", function (evt) {
        SelectSvcMenu = $('#page-OpportunityList').find('.SelectAll .ui-btn-active').attr("SvcId");
        g_OpportunityView_q2 = $('#page-OpportunityList').find(".txtsearch").val();
        SetListview($('#page-OpportunityList').find('.ulMainList'), SelectSvcMenu, g_OpportunityView_q2);
    });

    $(this).find('.liList').live("vclick", function (evt) {
        //g_OpportunityView_q1 = $(this).attr('q1');
        g_ContactView_q1 = $(this).attr('q1');
        $.mobile.changePage("/Opportunity/OpportunityView.html", {
            transition: _transition
        });

        $("#page-OpportunityView").data("q1", $(this).attr('q1'));

    });


});
$('#page-OpportunityList').live("pageshow", function (evt) {

    $(this).find('.btnsearch').trigger('vclick');
});
$('#page-OpportunityList').find('#aNew').live("vclick", function (evt) {



    var today = new Date();
    var v_year = today.getFullYear();
    var v_month = today.getMonth() + 1;
    var v_day = today.getDate();

    var v_month2;
    if (v_month < 10) {
        v_month2 = "0" + v_month.toString();
    }

    var v_date = v_year.toString() + "-"+v_month2 + "-"+v_day.toString();

    var $page = $('#page-OpportunityCreate');
    $page.find('#txtCOMPANY').val("");
    $page.find('#txtCLIID').val("");
    $page.find('#txtCALLNAME').val("");
    $page.find('#txtADDRESS').val("");
    $page.find('#txtTELNO1').val("");
    $page.find('#txtTELNO2').val("");
    $page.find('#txtTELNO3').val("");
    $page.find('#txtSALENAME').val("");
    $page.find('#selSALESTATE').val(6);
    $page.find('#dtSTATEDATE').val(v_date);
    $page.find('#txtPROB').val("");
    $page.find('#dtFORDDATE').val("");
    $page.find('#txtNEED').val("");
    $page.find('#txtSOLUTION').val("");
    $page.find('#txtCSTDESC').val("");

    $.mobile.changePage("/Opportunity/OpportunityCreate.html", { transition: _transition });
//    $.mobile.pageLoading(true);

    $('#page-OpportunityCreate').data("mode", "new");


});

$('#page-OpportunityView').live("pageshow", function (evt) {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1; // g_OpportunityView_q1;
    if (q2 == undefined) q2 = g_ContactView_q1; // g_OpportunityView_q2;
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    $('#page-OpportunityView').data("q1", q1);

    SetValue($('#page-OpportunityView').find('.DataUl'), 'OpportunityView', q1);
    SetListview($('#page-OpportunityView').find('.ulOpportunityKeymanList'), "OpportunityKeymanList", q1);
    //SetListview($('#page-OpportunityView').find('.ulOpportunityMeetList'), "OpportunityMeetList", q1);
    SetListview($('#page-OpportunityView').find('.ulOpportunityMeetList'), "OpportunityMeetList2", q1);


    var pl = new JSONClientParameters();
    pl.add("SvcID", "OpportunityView");
    var pstr = "<DataTable><Record>";
    pstr += "<p1>" + q1 + "</p1>";
    pstr += "<us>" + sm28 + "</us>";
    pstr += "</Record></DataTable>";
    pl.add("XmlParms", pstr);

    var _data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);
    var _OWNER = _data.Records[0].OWNER;

    if (_OWNER == sm28.replace("T", "")) {
        $(this).find('.btnModify').toggle(true);
        $(this).find('.btnDelete').toggle(true);
    } else {
        $(this).find('.btnModify').toggle(false);
        $(this).find('.btnDelete').toggle(false);
    }


    $(this).find('.btnsearch').live("vclick", function (evt) {
        //g_OpportunityView_q2 = $('#page-OpportunityView').find(".txtsearch").val();
        g_ContactView_q2 = $('#page-OpportunityView').find(".txtsearch").val();
        SetListview($('#page-OpportunityView').find('.ulMainList'), "OpportunityList", g_OpportunityView_q2);
    });

    $(this).find('.liList').live("vclick", function (evt) {
        q1 = $(this).attr('q1');
        SetValue($('#page-OpportunityView').find('.DataUl'), 'OpportunityView', q1);
        SetListview($('#page-OpportunityView').find('.ulOpportunityKeymanList'), "OpportunityKeymanList", q1);
        //SetListview($('#page-OpportunityView').find('.ulOpportunityMeetList'), "OpportunityMeetList", q1);
        SetListview($('#page-OpportunityView').find('.ulOpportunityMeetList'), "OpportunityMeetList2", q1);

        $('#page-OpportunityView').data("q1", q1);

        window.scrollTo(0, 0);
    });

    $(this).find('.liKeymanList').live("vclick", function (evt) {
        $.mobile.pageLoading();

        g_ContactView_q1 = $(this).attr('q1');
        //g_ContactView_q2 = $(this).attr('q2');
        $.mobile.changePage("/Account/ContactView.html", { transition: _transition });
        $.mobile.pageLoading(true);
    });

    $(this).find('.liMeetList').live("vclick", function (evt) {
        $.mobile.pageLoading();

        g_ContactView_q1 = $(this).attr('q1');
        g_ContactView_q2 = $(this).attr('q2');
        $.mobile.changePage("/Opportunity/OpportunityMeetView.html", { transition: _transition });
        $.mobile.pageLoading(true);
    });

    //kh 영업정보 수정
    $('#page-OpportunityView').find('.btnModify').live("vclick", function (evt) {
        var q1 = getUrlVars()["q1"];
        var q2 = getUrlVars()["q2"];
        if (q1 == undefined) q1 = g_AccountView_q1;
        if (q2 == undefined) q2 = g_AccountView_q2;
        if (q1 == undefined) q1 = $('#page-OpportunityView').data("q1");
        if (q1 == undefined) q1 = "0";
        if (q2 == undefined) q2 = "";




        $.mobile.changePage("/Opportunity/OpportunityModify.html", { transition: _transition });

        $('#page-OpportunityModify').data("mode", "edit");


    });

});

// 영업-접촉이력 상세보기 
$('#page-OpportunityMeetView').live("pageshow", function () {

    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined) q1 = "0";
    if (q2 == undefined) q2 = "";

    // 고객상세
    SetValue($('#page-OpportunityMeetView').find('.DataUl'), 'ContactMeetDetail', q2);

    // 접촉이력목록
    SetListview($('#page-OpportunityMeetView').find('.ulContactMeetList'), 'OpportunityMeetList2', q1);


    $(this).find('.liMeetList').live("vclick", function (evt) {
        
        //g_ContactView_q1 = $(this).attr('q1');
        g_ContactView_q2 = $(this).attr('q2');

        SetValue($('#page-OpportunityMeetView').find('.DataUl'), 'ContactMeetDetail', g_ContactView_q2);
    });


    $(this).find('.btnsearch').live("vclick", function (evt) {
        //g_OpportunityView_q2 = $('#page-OpportunityMeetView').find(".txtsearch").val();
        g_ContactView_q2 = $('#page-OpportunityMeetView').find(".txtsearch").val();

        SetListview($('#page-OpportunityMeetView').find('.ulMainList'), "OpportunityList", g_OpportunityView_q2);
    });

    $(this).find('.liList').live("vclick", function (evt) {
        //q1 = $(this).attr('q1');
        //SetValue($('#page-OpportunityMeetView').find('.DataUl'), 'OpportunityView', q1);
        //SetListview($('#page-OpportunityMeetView').find('.ulOpportunityKeymanList'), "OpportunityKeymanList", q1);
        //SetListview($('#page-OpportunityMeetView').find('.ulOpportunityMeetList'), "OpportunityMeetList2", q1);

        //$('#page-OpportunityMeetView').data("q1", q1);
        $.mobile.pageLoading();
        g_ContactView_q1 = $(this).attr('q1');
        //g_ContactView_q2 = $(this).attr('q2');
        $.mobile.changePage("/Opportunity/OpportunityLinkView.html", { transition: _transition });
        $.mobile.pageLoading(true);

        window.scrollTo(0, 0);
    });

});
//고객>영업 상세보기
$('#page-OpportunityLinkView').live("pagecreate", function () {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ContactView_q1;
    if (q2 == undefined) q2 = g_ContactView_q2;
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    SetValue($('#page-OpportunityLinkView').find('.DataUl'), 'OpportunityView', q1);
    SetListview($('#page-OpportunityLinkView .ulOpportunityKeymanList'), "OpportunityKeymanList", q1);
    SetListview($('#page-OpportunityLinkView .ulOpportunityMeetList'), "OpportunityMeetList", q1);


    $(this).find('.liKeymanList').live("vclick", function (evt) {
        $.mobile.pageLoading();

        g_ContactView_q1 = $(this).attr('q1');
        //g_ContactView_q2 = $(this).attr('q2');
        $.mobile.changePage("/Account/ContactView.html", { transition: _transition });
        $.mobile.pageLoading(true);
    });

    $(this).find('.liMeetList').live("vclick", function (evt) {
        $.mobile.pageLoading();

        //g_ContactView_q1 = $(this).attr('q1');
        g_ContactView_q2 = $(this).attr('q2');
        $.mobile.changePage("/Opportunity/OpportunityMeetView.html", { transition: _transition });
        //$.mobile.changePage("/Account/ContactMeetView.htm", { transition: _transition });
        $.mobile.pageLoading(true);
    });


    $(this).find('.btnsearch').live("vclick", function (evt) {
        //g_OpportunityView_q2 = $('#page-OpportunityLinkView').find(".txtsearch").val();
        g_ContactView_q2 = $('#page-OpportunityLinkView').find(".txtsearch").val();

        SetListview($('#page-OpportunityLinkView').find('.ulMainList'), "OpportunityList", g_OpportunityView_q2);
    });

    $(this).find('.liList').live("vclick", function (evt) {
        q1 = $(this).attr('q1');
        SetValue($('#page-OpportunityLinkView').find('.DataUl'), 'OpportunityView', q1);
        SetListview($('#page-OpportunityLinkView').find('.ulOpportunityKeymanList'), "OpportunityKeymanList", q1);
        SetListview($('#page-OpportunityLinkView').find('.ulOpportunityMeetList'), "OpportunityMeetList2", q1);

        $('#page-OpportunityLinkView').data("q1", q1);
       
    });

});


// -------------------------------------------------------------------------------------------
// Activate
// -------------------------------------------------------------------------------------------

$('#page-ActivateList').live("pagecreate", function () {
    $(this).find('.btnsearch').live("vclick", function (evt) {
        SelectSvcMenu = $('#page-ActivateList').find('.SelectAll .ui-btn-active').attr("SvcId");
        g_ActivateView_q2 = $('#page-ActivateList').find(".txtsearch").val();
        SetListview($('#page-ActivateList').find('.ulMainList'), SelectSvcMenu, g_ActivateView_q2);
    });

    $(this).find('.liList').live("vclick", function (evt) {
        g_ActivateView_q1 = $(this).attr('q1');
        $.mobile.changePage("/Activate/ActivateView.html", {
            transition: _transition
        });
    });

    $(this).find('.btnsearch').trigger('vclick');

});

$('#page-ActivateView').live("pageshow", function () {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_ActivateView_q1;
    if (q2 == undefined) q2 = g_ActivateView_q2;
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    SetValue($('#page-ActivateView').find('.DataUl'), 'ActivateView', q1);
    SetListview($('#page-ActivateView').find('.ulContactMeetList'), "ActivateMeetList", q1);

//    $(this).find(".txtsearch").val(q2);
//    SetListview($('#page-ActivateView').find('.ulMainList'), "ActivateList", q2);

    $(this).find('.btnsearch').live("vclick", function (evt) {
        g_ActivateView_q2 = $('#page-ActivateView').find(".txtsearch").val();
        SetListview($('#page-ActivateView').find('.ulMainList'), "ActivateList", g_ActivateView_q2);
    });

    $(this).find('.liList').live("vclick", function (evt) {
        q1 = $(this).attr('q1');
        SetValue($('#page-ActivateView').find('.DataUl'), 'ActivateView', q1);
        SetListview($('#page-ActivateView').find('.ulContactMeetList'), "ActivateMeetList", q1);
        window.scrollTo(0, 0);
    });

    $(this).find('.liMeetList').live("vclick", function (evt) {
        q1 = $(this).attr('q1');
        SetValue($('#page-ActivateView').find('.DataUl'), 'ActivateView', q1);
        window.scrollTo(0, 0);
    });


});

// -------------------------------------------------------------------------------------------
// BillList
// -------------------------------------------------------------------------------------------
$('#page-BillList').live("pagecreate", function () {

    $(this).find('.btnsearch').live("vclick", function (evt) {
        SelectSvcMenu = $('#page-BillList').find('.SelectAll .ui-btn-active').attr("SvcId");
        g_BillView_q2 = $('#page-BillList').find(".txtsearch").val();
        SetListview($('#page-BillList').find('.ulMainList'), SelectSvcMenu, g_BillView_q2);
    });

    $(this).find('.liList').live("vclick", function (evt) {
        g_BillView_q1 = $(this).attr('q1');
        $.mobile.changePage("/Opportunity/BillView.html", {
            transition: _transition
        });
    });

    $(this).find('.btnsearch').trigger('vclick');

});

$('#page-BillView').live("pageshow", function () {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_BillView_q1;
    if (q2 == undefined) q2 = g_BillView_q2;
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    SetValue($('#page-BillView').find('.DataUl'), 'BillView', q1);
    SetListview($('#page-BillView').find('.ulBillKeymanList'), "BillKeymanList", q1);
    

//    $(this).find(".txtsearch").val(q2);
//    SetListview($('#page-BillView').find('.ulMainList'), "BillList", q2);

    $(this).find('.btnsearch').live("vclick", function (evt) {
        g_ActivateView_q2 = $('#page-BillView').find(".txtsearch").val();
        SetListview($('#page-BillView').find('.ulMainList'), "BillList", g_BillView_q2);
    });

    $(this).find('.liList').live("vclick", function (evt) {
        q1 = $(this).attr('q1');
        SetValue($('#page-BillView').find('.DataUl'), 'BillView', q1);
        SetListview($('#page-BillView').find('.ulBillKeymanList'), "BillKeymanList", q1);
        window.scrollTo(0, 0);
    });


});

// -------------------------------------------------------------------------------------------
// OrderList
// -------------------------------------------------------------------------------------------

$('#page-OrderList').live("pagecreate", function () {
    SelectSvcMenu = $('#page-OrderList').find('.SelectAll .ui-btn-active').attr("SvcId");
    //SetListview($(this).find('.ulMainList'), "OrderList", "");
    SetListview($(this).find('.ulMainList'), SelectSvcMenu, "");

    $(this).find('.btnsearch').live("vclick", function (evt) {
        g_OrderView_q2 = $('#page-OrderList').find(".txtsearch").val();
        SelectSvcMenu = $('#page-OrderList').find('.SelectAll .ui-btn-active').attr("SvcId");

        //SetListview($('#page-OrderList').find('.ulMainList'), "OrderList", g_OrderView_q2);
        SetListview($('#page-OrderList').find('.ulMainList'), SelectSvcMenu, g_OrderView_q2);

    });

    $(this).find('.liList').live("vclick", function (evt) {
        g_OrderView_q1 = $(this).attr('q1');
        $.mobile.changePage("/Opportunity/OrderView.html", {
            transition: _transition
        });
    });
});


$('#page-OrderView').live("pageshow", function () {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_OrderView_q1;
    if (q2 == undefined) q2 = g_OrderView_q2;
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    SetValue($('#page-OrderView').find('.DataUl'), 'OrderView', q1);
    SetListview($('#page-OrderView').find('.ulOrderPrdList'), "OrderPrdList", q1);


//    $(this).find(".txtsearch").val(q2);
//    SetListview($('#page-OrderView').find('.ulMainList'), "OrderList", q2);

    $(this).find('.btnsearch').live("vclick", function (evt) {
        g_OrderView_q2 = $('#page-OrderView').find(".txtsearch").val();
        SetListview($('#page-OrderView').find('.ulMainList'), "OrderList", g_OrderView_q2);
    });

    $(this).find('.liList').live("vclick", function (evt) {
        q1 = $(this).attr('q1');
        SetValue($('#page-OrderView').find('.DataUl'), 'OrderView', q1);
        SetListview($('#page-OrderView').find('.ulOrderPrdList'), "OrderPrdList", q1);
        window.scrollTo(0, 0);
    });


});

// -------------------------------------------------------------------------------------------
// GroupList
// -------------------------------------------------------------------------------------------

$('#page-GroupList').live("pagecreate", function () {
    SelectSvcMenu = $('#page-GroupList').find('.SelectAll .ui-btn-active').attr("SvcId");
    SetListview($(this).find('.ulMainList'), SelectSvcMenu, "");
    //SetListview($(this).find('.ulMainList'), "GroupList", "");
   
    $(this).find('.btnsearch').live("vclick", function (evt) {
        SelectSvcMenu = $('#page-GroupList').find('.SelectAll .ui-btn-active').attr("SvcId");

        g_GroupView_q2 = $('#page-GroupList').find(".txtsearch").val();
        SetListview($('#page-GroupList').find('.ulMainList'), SelectSvcMenu, g_GroupView_q2);
        //SetListview($('#page-GroupList').find('.ulMainList'), "GroupList", g_GroupView_q2);
    });

    $(this).find('.liList').live("vclick", function (evt) {
        g_GroupView_q1 = $(this).attr('q1');
        $.mobile.changePage("/Utility/GroupView.html", {
            transition: _transition
        });
    });
});

$('#page-GroupView').live("pageshow", function () {
    var q1 = getUrlVars()["q1"];
    var q2 = getUrlVars()["q2"];
    if (q1 == undefined) q1 = g_GroupView_q1;
    if (q2 == undefined) q2 = g_GroupView_q2;
    if (q1 == undefined || q1 == "") q1 = "0";
    if (q2 == undefined || q2 == "") q2 = "";

    SetValue($('#page-GroupView').find('.DataUl'), 'GroupView', q1);
    SetListview($('#page-GroupView').find('.ulGroupContactList'), "GroupContactList", q1);


    //    $(this).find(".txtsearch").val(q2);
    //    SetListview($('#page-GroupView').find('.ulMainList'), "GroupList", q2);

    $(this).find('.btnsearch').live("vclick", function (evt) {
        g_GroupView_q2 = $('#page-GroupView').find(".txtsearch").val();
        SetListview($('#page-GroupView').find('.ulMainList'), "GroupList", g_GroupView_q2);
    });

    $(this).find('.liList').live("vclick", function (evt) {
        q1 = $(this).attr('q1');
        SetValue($('#page-GroupView').find('.DataUl'), 'GroupView', q1);
        SetListview($('#page-GroupView').find('.ulGroupContactList'), "GroupContactList", q1);
        window.scrollTo(0, 0);
    });

    $(this).find('.liContactList').live("vclick", function (evt) {
        g_ContactView_q1 = $(this).attr('q1');
        g_ContactView_q2 = "";
        $.mobile.changePage("/Account/ContactView.html", { transition: _transition });
    });

    //2012.03.20 kh: 선택한 그룹 sms 보내기 
    $(this).find('.SelectAll #aSMS').live("vclick", function (evt) {
        g_ContactView_q1 = q1;
        g_ContactView_q2 = "";


        $.mobile.changePage("/Utility/SMS.html", { transition: _transition });


        var pl = new JSONClientParameters();
        pl.add("SvcID", "GroupContactList");
        var pstr = "<DataTable><Record>";
        pstr += "<p1>" + q1 + "</p1>";
        pstr += "<us>" + sm28 + "</us>";
        pstr += "</Record></DataTable>";
        pl.add("XmlParms", pstr);

        var _data = PostJsonData("/bzService/DBProxy.asmx/execComm", pl, function (data) {
            if (data == undefined) return false;
            var Rows = data.Records.length;

            var i;
            i = 0;
            for (i; i < Rows; i++) {
                var _LI_ITEM = data.Records[i].LI_ITEM;

                $(_LI_ITEM).appendTo($('#page-SMS').find('.ulSendList'));
            }

            $('#page-SMS').find('.ulSendList').listview("refresh");

        });




    });
    $(this).find('.btnClear').live("vclick", function (evt) {
        alert("호출");
        $('#page-SMS').find('.ulSendList').remove();
    });
    //2012.03.20 kh: 선택한 그룹 mail 보내기 
    $(this).find('.SelectAll #aEMAIL').live("vclick", function (evt) {
        g_ContactView_q1 = q1;
        g_ContactView_q2 = "";


        $.mobile.changePage("/Utility/Mail.html", { transition: _transition });

        var pl = new JSONClientParameters();
        pl.add("SvcID", "GroupContactList");
        var pstr = "<DataTable><Record>";
        pstr += "<p1>" + q1 + "</p1>";
        pstr += "<us>" + sm28 + "</us>";
        pstr += "</Record></DataTable>";
        pl.add("XmlParms", pstr);

        var _data = PostJsonData("/bzService/DBProxy.asmx/execComm", pl, function (data) {
            if (data == undefined) return false;
            var Rows = data.Records.length;

            var i;
            i = 0;
            for (i; i < Rows; i++) {
                var _LI_ITEM = data.Records[i].LI_ITEM;

                $(_LI_ITEM).appendTo($('#page-Mail').find('.ulSendList'));
            }

            $('#page-Mail').find('.ulSendList').listview("refresh");

        });



    });


});

// -------------------------------------------------------------------------------------------
// 2012.03.23 kh 게시판 
// -------------------------------------------------------------------------------------------
$('#page-BoardPortalList').live("pagecreate", function () {
    SelectSvcMenu = $('#page-BoardPortalList').find('.SelectAll .ui-btn-active').attr("SvcId");
    g_ContactView_q2 = $('#page-BoardPortalList').find(".txtsearch").val();
    SetListview($('#page-BoardPortalList').find('.ulMainList'), SelectSvcMenu, g_ContactView_q2);

    $('#page-BoardPortalList').find('.SelectAll a').live("vclick", function () {
        SelectSvcMenu = $('#page-BoardPortalList').find('.SelectAll .ui-btn-active').attr("SvcId");
        g_ContactView_q2 = $('#page-BoardPortalList').find(".txtsearch").val();
        SetListview($('#page-BoardPortalList').find('.ulMainList'), SelectSvcMenu, g_ContactView_q2);

    });

});

// -------------------------------------------------------------------------------------------
// SMS
// -------------------------------------------------------------------------------------------

$('#page-SMS').live("pagecreate", function () {

    $(this).find('.btnsearch').live("vclick", function (evt) {
        SetListview($('#page-SMS').find('.ulContactList'), "SMSContactList", $('#page-SMS').find(".txtsearch").val());
    });

    $(this).find('.ulContactList .liContactList').live("vclick", function (evt) {
        $(this).parent().parent().parent().clone().appendTo($('#page-SMS').find('.ulSendList'));
        $('#page-SMS').find('.ulSendList').listview("refresh");
    });

    $(this).find('.ulSendList .liContactList').live("vclick", function (evt) {
        $(this).parent().parent().parent().remove();
        $('#page-SMS').find('.ulSendList').listview("refresh");
    });

});

// -------------------------------------------------------------------------------------------
// mail
// -------------------------------------------------------------------------------------------


$('#page-Mail').live("pagecreate", function () {

    $(this).find('.btnsearch').live("vclick", function (evt) {
        SetListview($('#page-Mail').find('.ulContactList'), "SMSContactList", $('#page-Mail').find(".txtsearch").val());
    });

    $(this).find('.ulContactList .liContactList').live("vclick", function (evt) {
        $(this).parent().parent().parent().clone().appendTo($('#page-Mail').find('.ulSendList'));
        $('#page-Mail').find('.ulSendList').listview("refresh");
    });

    $(this).find('.ulSendList .liContactList').live("vclick", function (evt) {
        $(this).parent().parent().parent().remove();
        $('#page-Mail').find('.ulSendList').listview("refresh");
    });

});


// -------------------------------------------------------------------------------------------
// login
// -------------------------------------------------------------------------------------------
var sm24 = "";
var sm26 = "";
var sm28 = "";

$('#page-Login').live("pageshow", function () {
    
});

$('#page-Login').live("pagecreate", function () {
   
    $(this).parent().find('input[type="text"]').val($.cookie('sm24'));
    $(this).parent().find('input[type="password"]').val($.cookie('sm36'));

    $(this).find('.btnsearch').live("vclick", function (evt) {
       
        sm24 = $(this).parent().find('input[type="text"]').val();
        sm36 = $(this).parent().find('input[type="password"]').val();
        var pstr = "<DataTable><Record><p1>" + sm24 + "</p1><p2>" + sm36 + "</p2></Record></DataTable>";

        var pl = new JSONClientParameters();
        pl.add("SvcID", "BoardList");
        pl.add("XmlParms", pstr);
        data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl)

        if (data.TRCOUNT > 0) {
            var DataRow = data.Records[0];
            sm26 = DataRow.USERNAME;
            sm28 = DataRow.USERID;
            if ($('#passcheckbox').attr('checked') == "checked") {
                $.cookie('sm24', sm24, { expires: 5 });
                $.cookie('sm36', sm36, { expires: 5 });
            }
            else {
                $.cookie('sm24', '');
                $.cookie('sm36', '');
            }
            
            $.mobile.changePage("/index.html");
            return true
        }
        alert("Login Fail.....");

    });
});

// -------------------------------------------------------------------------------------------
// init
// -------------------------------------------------------------------------------------------

$('#jqm-home').live("pageshow", function () {
    $(this).find('#sm26').html('User. ' + sm26);
    txt = "<p>Browser Version: " + navigator.appVersion + "</p>";
    $(this).find('#infoBrowse').html(txt);



    if (txt.indexOf("Mobile Safari") > -1) {
        _transition = "none"; //flip
    } else if (txt.indexOf("Chrome") > -1) {
        _transition = "none"; //flip
    } else if (txt.indexOf("Safari") > -1) {
        _transition = "none"; //flip
    }
    else {
        _transition = "none";
    }

    
    //create:2012.03.22 kh: 탑 메뉴 데이터 바인딩
    var pl = new JSONClientParameters();
    pl.add("SvcID", "MainList");
    var pstr = "<DataTable><Record>";
    pstr += "<us>" + sm28.replace("T","") + "</us>";
    pstr += "</Record></DataTable>";
    pl.add("XmlParms", pstr);

    var _data = PostJsonData("/bzService/DBProxy.asmx/execComm", pl, function (data) {
        if (data == undefined) return false;
        var Rows = data.Records.length;

        var i;
        i = 0;
        for (i; i < Rows; i++) {
            var _IDX = data.Records[i].IDX;
            var _CNT = data.Records[i].CNT;

            if (_IDX == "6") {
                $("#jqm-home a[SvcId='AccountList'] .ui-btn-text").html("결재(" + _CNT + ")");
            }
            if (_IDX == "4") {
                $("#jqm-home a[SvcId='ScheduleList'] .ui-btn-text").html("일정(" + _CNT + ")");
            }
            if (_IDX == "2") {
                $("#jqm-home a[SvcId='BoardList'] .ui-btn-text").html("게시(" + _CNT + ")");
            }

        }


    });
    



    /* 
    Chrome/12

    */
});

function CallTel(cstid, telno) {

    var pl = new JSONClientParameters();
    pl.add("SvcID", "ActivateCreate");
    var pstr = "<DataTable><Record>";
    pstr += "<p1>" + cstid + "</p1>";
    pstr += "<p2>" + '모바일전화접촉' + "</p2>";
    pstr += "<p3>0</p3>";
    pstr += "<p4>" + sm28.replace('T', '') + "</p4>";
    pstr += "</Record></DataTable>";
    pl.add("XmlParms", pstr);
    
   // PostStrSync("/bzService/DBProxy.asmx/execRun", pl)

    window.location.href = "tel:" + telno;
}
function CallTelM(cstid, telno, userid) {

    var pl = new JSONClientParameters();
    pl.add("SvcID", "ActivateCreate");
    var pstr = "<DataTable><Record>";
    pstr += "<p1>" + cstid + "</p1>";
    pstr += "<p2>" + '모바일전화접촉' + "</p2>";
    pstr += "<p3>0</p3>";
    pstr += "<p4>" + userid + "</p4>";
    pstr += "</Record></DataTable>";
    pl.add("XmlParms", pstr);

    // PostStrSync("/bzService/DBProxy.asmx/execRun", pl)

    window.location.href = "tel:" + telno;
}

function CallMail(cstid, eMail) {
    
    var pl = new JSONClientParameters();
    pl.add("SvcID", "ActivateCreate");
    var pstr = "<DataTable><Record>";
    pstr += "<p1>" + cstid + "</p1>";
    pstr += "<p2>" + '모바일메일접촉' + "</p2>";
    pstr += "<p3>0</p3>";
    pstr += "<p4>" + sm28.replace('T', '') + "</p4>";
    pstr += "</Record></DataTable>";
    pl.add("XmlParms", pstr);
    PostStrSync("/bzService/DBProxy.asmx/execRun", pl)
    
    window.location.href = 'mailto:' + eMail ;

}

$(document).bind("mobileinit", function () {
//    $.mobile.page.prototype.options.defaultPageTransition = 'none';
//    $.mobile.useFastClick = false;
//    $.mobile.page.prototype.options.degradeInputs.date = true;
//    $.mobile.loadingMessage = '페이지 로딩중...';
});


function SetValue(obj, SvcID, q1) {
    arr = q1.split(" ");

  //  $.mobile.pageLoading();
    var pl = new JSONClientParameters();
    pl.add("SvcID", SvcID);
    var pstr = "<DataTable><Record>";

    for (i = 1; i <= arr.length; i++) {
        pstr += "<p" + i + ">" + arr[i - 1] + "</p" + i + ">";
    }
    pstr += "<us>" + sm28 + "</us>";

    pstr += "</Record></DataTable>";
    // alert(pstr);
    pl.add("XmlParms", pstr);
    data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl)
    if (data.TRCOUNT > 0) {
        var DataRow = data.Records[0];
        $(obj).find('.Field').each(function (index) {
            _fld = $(this).attr('FIELD');
                $(this).html(DataRow[_fld]);
        });
        $(obj).find('.Fieldref').each(function (index) {
            _fld = $(this).attr('FIELD');
                $(this).attr('href',DataRow[_fld]);
        });
        $(obj).find('.FIELDPHOTO').each(function (index) {
            _fld = $(this).attr('FIELD');

           
            if (DataRow[_fld] != undefined) {
                $(this).toggle(true);
                $(this).attr('src', "/bzService/Down.aspx?q1=" + DataRow[_fld]);
            } else {
                $(this).toggle(false);
            }
        });
    }
   // $.mobile.pageLoading(true);

}

// -------------------------------------------------------------------------------------------
// file Upload
// -------------------------------------------------------------------------------------------
$('#page-FileUpload').live("pagecreate", function () {
    $(function () {
        //비동기 파일 전송
        var frm = $('#frmFile');
        frm.ajaxForm(FileuploadCallback);
        frm.submit(function () { $.mobile.pageLoading(); return false; });
    });
});

$('#page-FileUpload').live("pageshow", function () {
    $('#filecstid').val("");
    $('#Filename').val("");
    $(this).find('.FIELDPHOTO').attr("src", "");

    if (g_ContactView_q1 != undefined) {

        SetValue($('#page-FileUpload').find('.DataUl'), 'ContactView', g_ContactView_q1);



    }

    if ($(this).find('.FIELDPHOTO').attr('src') != "") {
        $(this).find('.btnDelete').toggle(true);
    } else {
        $(this).find('.btnDelete').toggle(false);
    }


});

//ajax error check
$(document).ajaxError(function (event, request) { if (request.status == 500) alert("데이터 저장시 오류 발생!! " + request.responseText); history.back(); });

//파일전송 후 콜백 함수
function FileuploadCallback(data, state) {

    if (data == "error") {
        alert("파일전송중 에러 발생!!");
    }
    //alert(data + " 파일전송 완료!!");
    $.mobile.pageLoading(true);
    history.back();
    return false;
}


$('#page-he').live("pageshow", function () {
    alert("준비중..");
    document.addEventListener("deviceready", onDeviceReady, false);

    // PhoneGap is ready
    //
    function onDeviceReady() {
        alert("준비완료");
        var element = document.getElementById('deviceProperties');

        element.innerHTML = 'Device Name: ' + device.name + '<br />' +
                            'Device PhoneGap: ' + device.phonegap + '<br />' +
                            'Device Platform: ' + device.platform + '<br />' +
                            'Device UUID: ' + device.uuid + '<br />' +
                            'Device Version: ' + device.version + '<br />';
    }

});


// 파일업로드 이벤트
function FileUpload() {
 //   $.mobile.pageLoading();
    if (!$("#Filename").val()) {
        alert("파일을 선택하세요.");
        $("#Filename").focus();
        return;
    }
    //파일전송
    var frm;
    frm = $('#frmFile');
    $('#filecstid').val(g_ContactView_q1);
    frm.attr("action", "/Account/UpLoad.aspx");
    frm.submit();
}
//사진삭제
function FileDelete() {

    var v_cstid;

    v_cstid = $("#page-FileUpload input[FIELD='PHOTOID']")[0].textContent;

    //alert("v_cstid:" + v_cstid);
    var v_confirm = confirm("삭제하시겠습니까?");

    if (v_confirm == true) {
       

        var pl = new JSONClientParameters();
        pl.add("SvcID", "ContactFileDelete");
        var pstr = "<DataTable><Record>";
        pstr += "<p1>" + v_cstid + "</p1>";
        pstr += "<us>" + sm28.replace('T', '') + "</us>";
        pstr += "</Record></DataTable>";
        pl.add("XmlParms", pstr);
        PostStrSync("/bzService/DBProxy.asmx/execRun", pl);

    }
    else {
        
    }

}

var canvas, context, tool;
var canvasContext;
$('#touch').live("pagecreate", function () {
//    if (window.addEventListener) {
//        window.addEventListener('load', InitEvent, false);
//    }

//    $(function () {



//        resizeCanvas();
//        $(window).resize(function () { resizeCanvas() });
//    

//    });
    resizeCanvas();
    InitEvent();
});

function resizeCanvas() {
    var w = window.innerWidth / 1.2;
    var h = window.innerHeight / 1.2;
    var canvasString = '<canvas id="drawCanvas" width="' + w + '" height="' + h + '">Canvas is not supported</canvas>';

    $('#contentholder').empty();
    $(canvasString).appendTo('#contentholder');
    // canvasContext = $('#drawCanvas').get(0).getContext('2d');

    //            $('#mainCanvas').bind('tap', function (event) {
    //                touchX = event.pageX;
    //                touchY = event.pageY;
    //                canvasContext.fillStyle = "#0f0";
    //                canvasContext.fillRect(touchX - 75, touchY - 50, 50, 50);

    //                canvasContext.font = "20pt Arial";
    //                canvasContext.fillText("X: " + touchX + " Y: " + touchY, touchX, touchY);
    //            });
}

function InitEvent() {

    canvas = document.getElementById('drawCanvas');
    if (!canvas) {
        alert("캔버스 객체를 찾을 수 없음");
        return;
    }
    if (!canvas.getContext) {
        alert("Drawing Contextf를 찾을 수 없음");
        return;
    }
    context = canvas.getContext('2d');
    if (!context) {
        alert("getContext() 함수를 호출 할 수 없음");
        return;
    }
    // Pencil tool 객체를 생성 한다.
    tool = new tool_pencil();
    canvas.addEventListener('mousedown', ev_canvas, false);
    canvas.addEventListener('mousemove', ev_canvas, false);
    canvas.addEventListener('mouseup', ev_canvas, false);

    alert("캔버스 활성화됨");
}

//function touchHandler(event) {
//    var touches = event.changedTouches,
//        first = touches[0],
//        type = "";

//    switch (event.type) {
//        case "touchstart": type = "mousedown"; break;
//        case "touchmove": type = "mousemove"; break;
//        case "touchend": type = "mouseup"; break;
//        default: return;
//    }

//    //initMouseEvent(type, canBubble, cancelable, view, clickCount,
//    //           screenX, screenY, clientX, clientY, ctrlKey,
//    //           altKey, shiftKey, metaKey, button, relatedTarget);

//    var simulatedEvent = document.createEvent("MouseEvent");
//    simulatedEvent.initMouseEvent(type, true, true, window, 1,
//                              first.screenX, first.screenY,
//                              first.clientX, first.clientY, false,
//                              false, false, false, 0/*left*/, null);

//    first.target.dispatchEvent(simulatedEvent);
//    event.preventDefault();
//}

//function init() {
//    document.addEventListener("touchstart", touchHandler, true);
//    document.addEventListener("touchmove", touchHandler, true);
//    document.addEventListener("touchend", touchHandler, true);
//    document.addEventListener("touchcancel", touchHandler, true);
//}

function tool_pencil() {
    var tool = this;
    this.started = false;
    // 마우스를 누르는 순간 그리기 작업을 시작 한다. 
    this.mousedown = function (ev) {
        context.beginPath();
        context.moveTo(ev._x, ev._y);
        tool.started = true;
    };
    // 마우스가 이동하는 동안 계속 호출하여 Canvas에 Line을 그려 나간다
    this.mousemove = function (ev) {
        if (tool.started) {
            context.lineTo(ev._x, ev._y);
            context.stroke();
        }
    };
    // 마우스 떼면 그리기 작업을 중단한다
    this.mouseup = function (ev) {
        if (tool.started) {
            tool.mousemove(ev);
            tool.started = false;
        }
    };
}
// Canvas요소 내의 좌표를 결정 한다.
function ev_canvas(ev) {
    if (ev.layerX || ev.layerX == 0) { // Firefox 브라우저
        ev._x = ev.layerX;
        ev._y = ev.layerY;
    }
    else if (ev.offsetX || ev.offsetX == 0) { // Opera 브라우저
        ev._x = ev.offsetX;
        ev._y = ev.offsetY;
    }
    // tool의 이벤트 핸들러를 호출한다.
    var func = tool[ev.type];
    if (func) {
        func(ev);
    }
    ev.preventDefault();
}

function SetListview(obj, SvcID, a) {
    $.mobile.pageLoading();
    obj.html("").listview("destroy").listview();
    arr = a.split(" ");
    var pl = new JSONClientParameters();
    pl.add("SvcID", SvcID);
    var pstr = "<DataTable><Record>";

    for (i = 1; i <= arr.length; i++){
        pstr += "<p"+i+">" + arr[i-1] + "</p"+i+">";
    }
    pstr += "<us>" + sm28 + "</us>";

    pstr += "</Record></DataTable>";
    // alert(pstr);
    pl.add("XmlParms", pstr);

    PostJsonData("/bzService/DBProxy.asmx/execComm", pl, function (data) {
        if (data.TRCOUNT > 0) {
            var Rows = data.Records.length;
            for (var i = 0; i < Rows; i++) {
                var DataRow = data.Records[i];
                var _html = DataRow.LI_ITEM;
                obj.append(_html);
            }
            obj.listview("destroy").listview();
        }

        $.mobile.pageLoading(true);
    });

}

function SetListviewSync(obj, SvcID, a) {
    $.mobile.pageLoading();
    obj.html("").listview("destroy").listview();
    arr = a.split(" ");
    var pl = new JSONClientParameters();
    pl.add("SvcID", SvcID);
    var pstr = "<DataTable><Record>";

    for (i = 1; i <= arr.length; i++) {
        pstr += "<p" + i + ">" + arr[i - 1] + "</p" + i + ">";
    }
    pstr += "<us>" + sm28 + "</us>";

    pstr += "</Record></DataTable>";
    // alert(pstr);
    pl.add("XmlParms", pstr);
    data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl)

    if (data.TRCOUNT > 0) {
        var Rows = data.Records.length;
        for (var i = 0; i < Rows; i++) {
            var DataRow = data.Records[i];
            var _html = DataRow.LI_ITEM;
            obj.append(_html);
        }
        obj.listview("destroy").listview();
    }

}

function SetCodeList(obj, SvcID, a) {
    obj.html("").selectmenu('refresh')
    arr = a.split(" ");
    var pl = new JSONClientParameters();
    pl.add("SvcID", SvcID);
    var pstr = "<DataTable><Record>";

    for (i = 1; i <= arr.length; i++) {
        pstr += "<p" + i + ">" + arr[i - 1] + "</p" + i + ">";
    }
    pstr += "<us>" + sm28 + "</us>";
    pstr += "</Record></DataTable>";
    // alert(pstr);
    pl.add("XmlParms", pstr);
    data = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl)

    if (data.TRCOUNT > 0) {
        var Rows = data.Records.length;
        for (var i = 0; i < Rows; i++) {
            var DataRow = data.Records[i];
            obj.append("<option value='" + DataRow.CCODE + "'>" + DataRow.CNAME + "</option>");
        }
        obj.selectmenu('refresh')
    }

    //$.mobile.pageLoading(true);
}

function SetMeetList(obj, SvcID, a) {
    obj.html("")
    var pl = new JSONClientParameters();
    pl.add("SvcID", SvcID);
    pl.add("XmlParms", "<DataTable><Record><p1>" + a + "</p1></Record></DataTable>");
    PostJsonData("/bzService/DBProxy.asmx/execComm", pl, function (data) {
        if (data.TRCOUNT > 0) {
            var Rows = data.Records.length;
            for (var i = 0; i < Rows; i++) {
                var DataRow = data.Records[i];
                var _html = DataRow.LI_ITEM;
                obj.append(_html);
            }
            obj.find('.liMeet').page();
        }
    });
}

$('div').live('pagebeforeshow', function (event, ui) {
    pageid = $(this).attr('id');
    //sm24 = "smkim";
    //alert("sm24 - "+sm24 +" , pageid = "+pageid);
    if (sm24 == "") {
        switch (pageid) {
            case 'page-Login':
                break;
            default:
                $.mobile.changePage("/Utility/login.html", {
                    transition: _transition,
                    reverse: false
                });
                return false;
                break;
        }
    }
});

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

//function getParameterByName(name, inputstring) {
//    var ips;
//    if (inputstring.length == 0)
//        ips = window.location;
//    else
//        ips = inputstring;
//    var match = RegExp('[?&]' + name + '=([^&]*)').exec(ips);
//    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));

//}